Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Jan 6, 2021
1 parent 325a84b commit 8d44b4b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
36 changes: 28 additions & 8 deletions spec/rspec/mocks/argument_matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,36 @@ def ==(other)
a_double.random_call(:a => "a", :b => "b")
end

it "matches against a hash submitted by reference and received by value" do
opts = {:a => "a", :b => "b"}
expect(a_double).to receive(:random_call).with(opts)
a_double.random_call(:a => "a", :b => "b")
if RUBY_VERSION < '3'
it "matches against a hash submitted by reference and received by value in Ruby 2" do
opts = {:a => "a", :b => "b"}
expect(a_double).to receive(:random_call).with(opts)
a_double.random_call(:a => "a", :b => "b")
end
else
it "fails to match against a hash submitted by reference and received by value in Ruby 3", :reset => true do
opts = {:a => "a", :b => "b"}
expect(a_double).to receive(:random_call).with(opts)
expect do
a_double.random_call(:a => "a", :b => "b")
end.to fail_with(/expected: \(\{:a=>"a", :b=>"b"|:b=>"b", :a=>"a"\}\)/)
end
end

it "matches against a hash submitted by value and received by reference" do
opts = {:a => "a", :b => "b"}
expect(a_double).to receive(:random_call).with(:a => "a", :b => "b")
a_double.random_call(opts)
if RUBY_VERSION < '3'
it "matches against a hash submitted by value and received by reference in Ruby 2" do
opts = {:a => "a", :b => "b"}
expect(a_double).to receive(:random_call).with(:a => "a", :b => "b")
a_double.random_call(opts)
end
else
it "fails to match against a hash submitted by value and received by reference in Ruby 3", :reset => true do
opts = {:a => "a", :b => "b"}
expect(a_double).to receive(:random_call).with(:a => "a", :b => "b")
expect do
a_double.random_call(opts)
end.to fail_with(/expected: \(\{(:a=>\"a\", :b=>\"b\"|:b=>\"b\", :a=>\"a\")\}\)/)
end
end

it "fails for a hash w/ wrong values", :reset => true do
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/partial_double_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def call(name)
it "can accept an inner hash as a message argument" do
hash = {:a => {:key => "value"}}
expect(object).to receive(:foobar).with(:key => "value").and_return(1)
expect(object.foobar(hash[:a])).to equal(1)
expect(object.foobar(**hash[:a])).to equal(1)
end

it "can create a positive message expectation" do
Expand Down
10 changes: 6 additions & 4 deletions spec/rspec/mocks/should_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,14 @@ def use_rspec_mocks
let(:expected_arguments) {
[
/Using.*without explicitly enabling/,
{:replacement => "the new `:expect` syntax or explicitly enable `:should`"}
]
}
let(:expected_keywords) {
{:replacement => "the new `:expect` syntax or explicitly enable `:should`"}
}

it "it warns about should once, regardless of how many times it is called" do
expect(RSpec).to receive(:deprecate).with(*expected_arguments)
expect(RSpec).to receive(:deprecate).with(*expected_arguments, **expected_keywords)
o = Object.new
o2 = Object.new
o.should_receive(:bees)
Expand All @@ -482,15 +484,15 @@ def use_rspec_mocks
end

it "warns about should not once, regardless of how many times it is called" do
expect(RSpec).to receive(:deprecate).with(*expected_arguments)
expect(RSpec).to receive(:deprecate).with(*expected_arguments, **expected_keywords)
o = Object.new
o2 = Object.new
o.should_not_receive(:bees)
o2.should_not_receive(:bees)
end

it "warns about stubbing once, regardless of how many times it is called" do
expect(RSpec).to receive(:deprecate).with(*expected_arguments)
expect(RSpec).to receive(:deprecate).with(*expected_arguments, **expected_keywords)
o = Object.new
o2 = Object.new

Expand Down

0 comments on commit 8d44b4b

Please sign in to comment.