Skip to content

Commit

Permalink
Move to Ruby 3.0, and RSpec expect syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jun 10, 2023
1 parent 445d0c5 commit 4f0ebc9
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 150 deletions.
12 changes: 10 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require:
- rubocop-rspec
- rubocop-performance

AllCops:
DisabledByDefault: false
TargetRubyVersion: 2.5
TargetRubyVersion: 3.0
NewCops: enable
SuggestExtensions: false
Exclude:
- 'xpath.gemspec'

Expand Down Expand Up @@ -123,6 +125,9 @@ Style/Documentation:
Style/EvenOdd:
Enabled: false

Style/QuotedSymbols:
Enabled: false

Lint/BooleanSymbol:
Enabled: false

Expand All @@ -149,3 +154,6 @@ RSpec/DescribeClass:

RSpec/FilePath:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false
2 changes: 1 addition & 1 deletion lib/xpath/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def with_element_conditions(expression, element_names)
end

def valid_xml_name?(name)
name =~ /^[a-zA-Z_:][a-zA-Z0-9_:.\-]*$/
name =~ /^[a-zA-Z_:][a-zA-Z0-9_:.-]*$/
end
end
end
2 changes: 1 addition & 1 deletion lib/xpath/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def each(&block)
arguments.each(&block)
end

def method_missing(*args) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
def method_missing(*args) # rubocop:disable Style/MissingRespondToMissing
XPath::Union.new(*arguments.map { |e| e.send(*args) })
end

Expand Down
4 changes: 0 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@

require 'xpath'
require 'pry'

RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }
end
16 changes: 8 additions & 8 deletions spec/union_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@expr1 = XPath.generate { |x| x.descendant(:p) }
@expr2 = XPath.generate { |x| x.descendant(:div) }
@collection = XPath::Union.new(@expr1, @expr2)
@collection.expressions.should eq [@expr1, @expr2]
expect(@collection.expressions).to eq [@expr1, @expr2]
end
end

Expand All @@ -22,7 +22,7 @@
@collection = XPath::Union.new(@expr1, @expr2)
exprs = []
@collection.each { |expr| exprs << expr }
exprs.should eq [@expr1, @expr2]
expect(exprs).to eq [@expr1, @expr2]
end
end

Expand All @@ -31,7 +31,7 @@
@expr1 = XPath.generate { |x| x.descendant(:p) }
@expr2 = XPath.generate { |x| x.descendant(:div) }
@collection = XPath::Union.new(@expr1, @expr2)
@collection.map(&:expression).should eq %i[descendant descendant]
expect(@collection.map(&:expression)).to eq %i[descendant descendant]
end
end

Expand All @@ -41,9 +41,9 @@
@expr2 = XPath.generate { |x| x.descendant(:div).where(x.attr(:id) == 'foo') }
@collection = XPath::Union.new(@expr1, @expr2)
@results = doc.xpath(@collection.to_xpath)
@results[0][:title].should eq 'fooDiv'
@results[1].text.should eq 'Blah'
@results[2].text.should eq 'Bax'
expect(@results[0][:title]).to eq 'fooDiv'
expect(@results[1].text).to eq 'Blah'
expect(@results[2].text).to eq 'Bax'
end
end

Expand All @@ -55,9 +55,9 @@
@xpath1 = @collection.where(XPath.attr(:id) == 'foo').to_xpath
@xpath2 = @collection.where(XPath.attr(:id) == 'fooDiv').to_xpath
@results = doc.xpath(@xpath1)
@results[0][:title].should eq 'fooDiv'
expect(@results[0][:title]).to eq 'fooDiv'
@results = doc.xpath(@xpath2)
@results[0][:id].should eq 'fooDiv'
expect(@results[0][:id]).to eq 'fooDiv'
end
end
end
Loading

0 comments on commit 4f0ebc9

Please sign in to comment.