Skip to content

Commit 6f1599d

Browse files
committed
Merge pull request #2825 from rspec/ruby-3.4-v2
Ruby 3.4 v2
1 parent fece159 commit 6f1599d

File tree

9 files changed

+99
-24
lines changed

9 files changed

+99
-24
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
RAILS_VERSION: 'main'
4646

4747
# Rails 8.0 builds >= 3.2
48+
- ruby: 3.4.0-rc1
49+
env:
50+
RAILS_VERSION: '~> 8.0.0'
4851
- ruby: 3.3
4952
env:
5053
RAILS_VERSION: '~> 8.0.0'

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ gem 'ffi', '> 1.15.5'
1616
gem 'rake', '> 12'
1717
gem 'rubocop', '~> 1.28.2'
1818

19+
if RUBY_VERSION.to_f > 3.3
20+
gem 'cucumber', git: 'https://github.com/cucumber/cucumber-ruby', branch: 'main'
21+
end
22+
1923
custom_gemfile = File.expand_path('Gemfile-custom', __dir__)
2024
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)
2125

lib/rspec/rails/matchers/have_enqueued_mail.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ def unmatching_mail_jobs
129129
end
130130

131131
def unmatching_mail_jobs_message
132-
msg = "Queued deliveries:"
132+
messages = ["Queued deliveries:"]
133133

134134
unmatching_mail_jobs.each do |job|
135-
msg << "\n #{mail_job_message(job)}"
135+
messages << " #{mail_job_message(job)}"
136136
end
137137

138-
msg
138+
messages.join("\n")
139139
end
140140

141141
def mail_job_message(job)

rspec-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ Gem::Specification.new do |s|
5555

5656
s.add_development_dependency 'ammeter', '~> 1.1.5'
5757
s.add_development_dependency 'aruba', '~> 0.14.12'
58-
s.add_development_dependency 'cucumber', '~> 7.0'
58+
s.add_development_dependency 'cucumber', '> 7.0'
5959
end

spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,16 @@ def broadcast(stream, msg)
248248
end
249249

250250
it "has an appropriate description including the matcher's description when qualified with `#with` and a composable matcher" do
251-
expect(
252-
have_broadcasted_to("my_stream")
251+
description = have_broadcasted_to("my_stream")
253252
.from_channel(channel)
254253
.with(a_hash_including(a: :b))
255254
.description
256-
).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {:a => :b}")
255+
256+
if RUBY_VERSION >= '3.4'
257+
expect(description).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {a: :b}")
258+
else
259+
expect(description).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {:a => :b}")
260+
end
257261
end
258262
end
259263
end

spec/rspec/rails/matchers/be_a_new_spec.rb

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ def new_record?; true; end
7171
end
7272

7373
it "fails" do
74+
message =
75+
if RUBY_VERSION >= '3.4'
76+
"attribute {\"foo\" => (a string matching \"bar\")} was not set on #{record.inspect}"
77+
else
78+
"attribute {\"foo\"=>(a string matching \"bar\")} was not set on #{record.inspect}"
79+
end
7480
expect {
7581
expect(record).to be_a_new(record.class).with(
7682
foo: a_string_matching("bar"))
77-
}.to raise_error("attribute {\"foo\"=>(a string matching \"bar\")} was not set on #{record.inspect}")
83+
}.to raise_error(message)
7884
end
7985

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

102108
context "only one matcher present in actual" do
103109
it "fails" do
110+
message =
111+
if RUBY_VERSION >= '3.4'
112+
"attribute {\"bar\" => (a string matching \"barn\")} was not set on #{record.inspect}"
113+
else
114+
"attribute {\"bar\"=>(a string matching \"barn\")} was not set on #{record.inspect}"
115+
end
104116
expect {
105117
expect(record).to be_a_new(record.class).with(
106118
foo: a_string_matching("foo"),
107119
bar: a_string_matching("barn")
108120
)
109-
}.to raise_error("attribute {\"bar\"=>(a string matching \"barn\")} was not set on #{record.inspect}")
121+
}.to raise_error(message)
110122
end
111123
end
112124
end
@@ -118,19 +130,29 @@ def new_record?; true; end
118130
expect(record).to be_a_new(record.class).with(zoo: 'zoo', car: 'car')
119131
}.to raise_error { |e|
120132
expect(e.message).to match(/attributes \{.*\} were not set on #{Regexp.escape record.inspect}/)
121-
expect(e.message).to match(/"zoo"=>"zoo"/)
122-
expect(e.message).to match(/"car"=>"car"/)
133+
if RUBY_VERSION >= '3.4'
134+
expect(e.message).to match(/"zoo" => "zoo"/)
135+
expect(e.message).to match(/"car" => "car"/)
136+
else
137+
expect(e.message).to match(/"zoo"=>"zoo"/)
138+
expect(e.message).to match(/"car"=>"car"/)
139+
end
123140
}
124141
end
125142
end
126143

127144
context "one attribute value not the same" do
128145
it "fails" do
146+
message =
147+
if RUBY_VERSION >= '3.4'
148+
%(attribute {"foo" => "bar"} was not set on #{record.inspect})
149+
else
150+
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
151+
end
152+
129153
expect {
130154
expect(record).to be_a_new(record.class).with(foo: 'bar')
131-
}.to raise_error(
132-
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
133-
)
155+
}.to raise_error(message)
134156
end
135157
end
136158
end
@@ -166,20 +188,30 @@ def new_record?; false; end
166188
expect(record).to be_a_new(String).with(zoo: 'zoo', car: 'car')
167189
}.to raise_error { |e|
168190
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}/)
169-
expect(e.message).to match(/"zoo"=>"zoo"/)
170-
expect(e.message).to match(/"car"=>"car"/)
191+
if RUBY_VERSION >= '3.4'
192+
expect(e.message).to match(/"zoo" => "zoo"/)
193+
expect(e.message).to match(/"car" => "car"/)
194+
else
195+
expect(e.message).to match(/"zoo"=>"zoo"/)
196+
expect(e.message).to match(/"car"=>"car"/)
197+
end
171198
}
172199
end
173200
end
174201

175202
context "one attribute value not the same" do
176203
it "fails" do
204+
message =
205+
"expected #{record.inspect} to be a new String and " +
206+
if RUBY_VERSION >= '3.4'
207+
%(attribute {"foo" => "bar"} was not set on #{record.inspect})
208+
else
209+
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
210+
end
211+
177212
expect {
178213
expect(record).to be_a_new(String).with(foo: 'bar')
179-
}.to raise_error(
180-
"expected #{record.inspect} to be a new String and " +
181-
%(attribute {"foo"=>"bar"} was not set on #{record.inspect})
182-
)
214+
}.to raise_error(message)
183215
end
184216
end
185217
end

spec/rspec/rails/matchers/be_routable_spec.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@
1818

1919
it "fails if routes do not recognize the path" do
2020
allow(routes).to receive(:recognize_path) { raise ActionController::RoutingError, 'ignore' }
21+
22+
message =
23+
if RUBY_VERSION >= '3.4'
24+
/expected \{get: "\/a\/path"\} to be routable/
25+
else
26+
/expected \{:get=>"\/a\/path"\} to be routable/
27+
end
28+
2129
expect do
2230
expect({ get: "/a/path" }).to be_routable
23-
end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
31+
end.to raise_error(message)
2432
end
2533
end
2634

@@ -35,9 +43,17 @@
3543

3644
it "fails if routes recognize the path" do
3745
allow(routes).to receive(:recognize_path) { { controller: "foo" } }
46+
47+
message =
48+
if RUBY_VERSION >= '3.4'
49+
/expected \{get: "\/a\/path"\} not to be routable, but it routes to \{controller: "foo"\}/
50+
else
51+
/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/
52+
end
53+
3854
expect do
3955
expect({ get: "/a/path" }).not_to be_routable
40-
end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
56+
end.to raise_error(message)
4157
end
4258
end
4359
end

spec/rspec/rails/matchers/route_to_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ def assert_recognizes(*)
99
it "provides a description" do
1010
matcher = route_to("these" => "options")
1111
matcher.matches?(get: "path")
12-
expect(matcher.description).to eq("route {:get=>\"path\"} to {\"these\"=>\"options\"}")
12+
13+
description =
14+
if RUBY_VERSION >= '3.4'
15+
"route {get: \"path\"} to {\"these\" => \"options\"}"
16+
else
17+
"route {:get=>\"path\"} to {\"these\"=>\"options\"}"
18+
end
19+
20+
expect(matcher.description).to eq(description)
1321
end
1422

1523
it "delegates to assert_recognizes" do
@@ -107,9 +115,16 @@ def assert_recognizes(*)
107115
context "with should_not" do
108116
context "when assert_recognizes passes" do
109117
it "fails with custom message" do
118+
message =
119+
if RUBY_VERSION >= '3.4'
120+
/expected \{get: "path"\} not to route to \{"these" => "options"\}/
121+
else
122+
/expected \{:get=>"path"\} not to route to \{"these"=>"options"\}/
123+
end
124+
110125
expect {
111126
expect({ get: "path" }).not_to route_to("these" => "options")
112-
}.to raise_error(/expected \{:get=>"path"\} not to route to \{"these"=>"options"\}/)
127+
}.to raise_error(message)
113128
end
114129
end
115130

spec/sanity_check_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def with_clean_env
2929
.to match(/uninitialized constant RSpec::Support/)
3030
.or match(/undefined method `require_rspec_core' for RSpec::Support:Module/)
3131
.or match(/undefined method `require_rspec_core' for module RSpec::Support/)
32+
.or match(/undefined method 'require_rspec_core' for module RSpec::Support/)
3233

3334
expect($?.exitstatus).to eq(1)
3435
end

0 commit comments

Comments
 (0)