Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to Ruby 3.0, and RSpec expect syntax #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will download a prebuilt Ruby version, install dependencies and
# run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Build

"on": push

env:
RUBYOPTS: "--disable-did-you-mean"
JAVA_OPTS: "-Djava.security.egd=file:/dev/urandom"

jobs:
rspec:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby: ["3.0", "3.1", "3.2", "jruby"]

steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rake
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
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

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