Skip to content

Commit

Permalink
RSpec 3.11.0+ distinguishes between hashed and Ruby 3 keywords
Browse files Browse the repository at this point in the history
This is due to change in RSpec [[1]], which cuases issues such as:

~~~
  1) MultiJson default options sets both load and dump options
     Failure/Error: self.load_options = self.dump_options = value

       MultiJson received :dump_options= with unexpected arguments
         expected: ({:foo=>"bar"})
              got: ({:foo=>"bar"})
     # ./lib/multi_json.rb:15:in `default_options='
     # ./spec/multi_json_spec.rb:171:in `block (4 levels) in <top (required)>'
     # /builddir/build/BUILD/spec/spec_helper.rb:12:in `silence_warnings'
     # ./spec/multi_json_spec.rb:171:in `block (3 levels) in <top (required)>'
~~~

Fixes intridea#203

[1]: rspec/rspec-mocks#1394
  • Loading branch information
voxik committed Sep 6, 2022
1 parent 9cc8710 commit 27732ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions spec/multi_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
end

it 'sets both load and dump options' do
expect(MultiJson).to receive(:dump_options=).with(:foo => 'bar')
expect(MultiJson).to receive(:load_options=).with(:foo => 'bar')
expect(MultiJson).to receive(:dump_options=).with({:foo => 'bar'})
expect(MultiJson).to receive(:load_options=).with({:foo => 'bar'})
silence_warnings { MultiJson.default_options = {:foo => 'bar'} }
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/shared/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
before { MultiJson.dump_options = MultiJson.adapter.dump_options = {} }

after do
expect(MultiJson.adapter.instance).to receive(:dump).with(1, :foo => 'bar', :fizz => 'buzz')
expect(MultiJson.adapter.instance).to receive(:dump).with(1, {:foo => 'bar', :fizz => 'buzz'})
MultiJson.dump(1, :fizz => 'buzz')
MultiJson.dump_options = MultiJson.adapter.dump_options = nil
end
Expand Down Expand Up @@ -100,8 +100,8 @@
end

it 'passes options to the adapter' do
expect(MultiJson.adapter).to receive(:dump).with('foo', :bar => :baz)
MultiJson.dump('foo', :bar => :baz)
expect(MultiJson.adapter).to receive(:dump).with('foo', {:bar => :baz})
MultiJson.dump('foo', {:bar => :baz})
end

it 'dumps custom objects that implement to_json' do
Expand All @@ -128,7 +128,7 @@ def to_json(*)
before { MultiJson.load_options = MultiJson.adapter.load_options = {} }

after do
expect(MultiJson.adapter.instance).to receive(:load).with('1', :foo => 'bar', :fizz => 'buzz')
expect(MultiJson.adapter.instance).to receive(:load).with('1', {:foo => 'bar', :fizz => 'buzz'})
MultiJson.load('1', :fizz => 'buzz')
MultiJson.load_options = MultiJson.adapter.load_options = nil
end
Expand Down
4 changes: 2 additions & 2 deletions spec/shared/json_common_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
describe 'with :indent option' do
it 'passes it on dump' do
object = 'foo'
expect(object).to receive(:to_json).with(:indent => "\t")
expect(object).to receive(:to_json).with({:indent => "\t"})
MultiJson.dump(object, :indent => "\t")
end
end
end

describe '.load' do
it 'passes :quirks_mode option' do
expect(::JSON).to receive(:parse).with('[123]', :quirks_mode => false, :create_additions => false)
expect(::JSON).to receive(:parse).with('[123]', {:quirks_mode => false, :create_additions => false})
MultiJson.load('[123]', :quirks_mode => false)
end
end
Expand Down

0 comments on commit 27732ab

Please sign in to comment.