Skip to content

Commit

Permalink
Merge pull request #2825 from rspec/ruby-3.4-v2
Browse files Browse the repository at this point in the history
Ruby 3.4 v2
  • Loading branch information
JonRowe authored Dec 21, 2024
2 parents 2bdca15 + daae082 commit f31e5c5
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
RAILS_VERSION: 'main'

# Rails 8.0 builds >= 3.2
- ruby: 3.4.0-rc1
env:
RAILS_VERSION: '~> 8.0.0'
- ruby: 3.3
env:
RAILS_VERSION: '~> 8.0.0'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ gem 'ffi', '> 1.15.5'
gem 'rake', '> 12'
gem 'rubocop', '~> 1.28.2'

if RUBY_VERSION.to_f > 3.3
gem 'cucumber', git: '/~https://github.com/cucumber/cucumber-ruby', branch: 'main'
end

custom_gemfile = File.expand_path('Gemfile-custom', __dir__)
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)

Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/rails/matchers/have_enqueued_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def unmatching_mail_jobs
end

def unmatching_mail_jobs_message
msg = "Queued deliveries:"
messages = ["Queued deliveries:"]

unmatching_mail_jobs.each do |job|
msg << "\n #{mail_job_message(job)}"
messages << " #{mail_job_message(job)}"
end

msg
messages.join("\n")
end

def mail_job_message(job)
Expand Down
2 changes: 1 addition & 1 deletion rspec-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ Gem::Specification.new do |s|

s.add_development_dependency 'ammeter', '~> 1.1.5'
s.add_development_dependency 'aruba', '~> 0.14.12'
s.add_development_dependency 'cucumber', '~> 7.0'
s.add_development_dependency 'cucumber', '> 7.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,16 @@ def broadcast(stream, msg)
end

it "has an appropriate description including the matcher's description when qualified with `#with` and a composable matcher" do
expect(
have_broadcasted_to("my_stream")
description = have_broadcasted_to("my_stream")
.from_channel(channel)
.with(a_hash_including(a: :b))
.description
).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {:a => :b}")

if RUBY_VERSION >= '3.4'
expect(description).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {a: :b}")
else
expect(description).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {:a => :b}")
end
end
end
end
58 changes: 45 additions & 13 deletions spec/rspec/rails/matchers/be_a_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ def new_record?; true; end
end

it "fails" do
message =
if RUBY_VERSION >= '3.4'
"attribute {\"foo\" => (a string matching \"bar\")} was not set on #{record.inspect}"
else
"attribute {\"foo\"=>(a string matching \"bar\")} was not set on #{record.inspect}"
end
expect {
expect(record).to be_a_new(record.class).with(
foo: a_string_matching("bar"))
}.to raise_error("attribute {\"foo\"=>(a string matching \"bar\")} was not set on #{record.inspect}")
}.to raise_error(message)
end

context "matcher is wrong type" do
Expand All @@ -101,12 +107,18 @@ def new_record?; true; end

context "only one matcher present in actual" do
it "fails" do
message =
if RUBY_VERSION >= '3.4'
"attribute {\"bar\" => (a string matching \"barn\")} was not set on #{record.inspect}"
else
"attribute {\"bar\"=>(a string matching \"barn\")} was not set on #{record.inspect}"
end
expect {
expect(record).to be_a_new(record.class).with(
foo: a_string_matching("foo"),
bar: a_string_matching("barn")
)
}.to raise_error("attribute {\"bar\"=>(a string matching \"barn\")} was not set on #{record.inspect}")
}.to raise_error(message)
end
end
end
Expand All @@ -118,19 +130,29 @@ def new_record?; true; end
expect(record).to be_a_new(record.class).with(zoo: 'zoo', car: 'car')
}.to raise_error { |e|
expect(e.message).to match(/attributes \{.*\} were not set on #{Regexp.escape record.inspect}/)
expect(e.message).to match(/"zoo"=>"zoo"/)
expect(e.message).to match(/"car"=>"car"/)
if RUBY_VERSION >= '3.4'
expect(e.message).to match(/"zoo" => "zoo"/)
expect(e.message).to match(/"car" => "car"/)
else
expect(e.message).to match(/"zoo"=>"zoo"/)
expect(e.message).to match(/"car"=>"car"/)
end
}
end
end

context "one attribute value not the same" do
it "fails" do
message =
if RUBY_VERSION >= '3.4'
%(attribute {"foo" => "bar"} was not set on #{record.inspect})
else
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
end

expect {
expect(record).to be_a_new(record.class).with(foo: 'bar')
}.to raise_error(
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
)
}.to raise_error(message)
end
end
end
Expand Down Expand Up @@ -166,20 +188,30 @@ def new_record?; false; end
expect(record).to be_a_new(String).with(zoo: 'zoo', car: 'car')
}.to raise_error { |e|
expect(e.message).to match(/expected #{Regexp.escape record.inspect} to be a new String and attributes \{.*\} were not set on #{Regexp.escape record.inspect}/)
expect(e.message).to match(/"zoo"=>"zoo"/)
expect(e.message).to match(/"car"=>"car"/)
if RUBY_VERSION >= '3.4'
expect(e.message).to match(/"zoo" => "zoo"/)
expect(e.message).to match(/"car" => "car"/)
else
expect(e.message).to match(/"zoo"=>"zoo"/)
expect(e.message).to match(/"car"=>"car"/)
end
}
end
end

context "one attribute value not the same" do
it "fails" do
message =
"expected #{record.inspect} to be a new String and " +
if RUBY_VERSION >= '3.4'
%(attribute {"foo" => "bar"} was not set on #{record.inspect})
else
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
end

expect {
expect(record).to be_a_new(String).with(foo: 'bar')
}.to raise_error(
"expected #{record.inspect} to be a new String and " +
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
)
}.to raise_error(message)
end
end
end
Expand Down
20 changes: 18 additions & 2 deletions spec/rspec/rails/matchers/be_routable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@

it "fails if routes do not recognize the path" do
allow(routes).to receive(:recognize_path) { raise ActionController::RoutingError, 'ignore' }

message =
if RUBY_VERSION >= '3.4'
/expected \{get: "\/a\/path"\} to be routable/
else
/expected \{:get=>"\/a\/path"\} to be routable/
end

expect do
expect({ get: "/a/path" }).to be_routable
end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
end.to raise_error(message)
end
end

Expand All @@ -35,9 +43,17 @@

it "fails if routes recognize the path" do
allow(routes).to receive(:recognize_path) { { controller: "foo" } }

message =
if RUBY_VERSION >= '3.4'
/expected \{get: "\/a\/path"\} not to be routable, but it routes to \{controller: "foo"\}/
else
/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/
end

expect do
expect({ get: "/a/path" }).not_to be_routable
end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
end.to raise_error(message)
end
end
end
19 changes: 17 additions & 2 deletions spec/rspec/rails/matchers/route_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ def assert_recognizes(*)
it "provides a description" do
matcher = route_to("these" => "options")
matcher.matches?(get: "path")
expect(matcher.description).to eq("route {:get=>\"path\"} to {\"these\"=>\"options\"}")

description =
if RUBY_VERSION >= '3.4'
"route {get: \"path\"} to {\"these\" => \"options\"}"
else
"route {:get=>\"path\"} to {\"these\"=>\"options\"}"
end

expect(matcher.description).to eq(description)
end

it "delegates to assert_recognizes" do
Expand Down Expand Up @@ -107,9 +115,16 @@ def assert_recognizes(*)
context "with should_not" do
context "when assert_recognizes passes" do
it "fails with custom message" do
message =
if RUBY_VERSION >= '3.4'
/expected \{get: "path"\} not to route to \{"these" => "options"\}/
else
/expected \{:get=>"path"\} not to route to \{"these"=>"options"\}/
end

expect {
expect({ get: "path" }).not_to route_to("these" => "options")
}.to raise_error(/expected \{:get=>"path"\} not to route to \{"these"=>"options"\}/)
}.to raise_error(message)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/sanity_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def with_clean_env
.to match(/uninitialized constant RSpec::Support/)
.or match(/undefined method `require_rspec_core' for RSpec::Support:Module/)
.or match(/undefined method `require_rspec_core' for module RSpec::Support/)
.or match(/undefined method 'require_rspec_core' for module RSpec::Support/)

expect($?.exitstatus).to eq(1)
end
Expand Down

0 comments on commit f31e5c5

Please sign in to comment.