diff --git a/Rakefile b/Rakefile index 492f66fb4..3258f0cf6 100644 --- a/Rakefile +++ b/Rakefile @@ -26,7 +26,7 @@ end namespace :clobber do desc "remove generated rbc files" task :rbc do - Dir['**/*.rbc'].each {|f| File.delete(f)} + Dir['**/*.rbc'].each { |f| File.delete(f) } end end @@ -40,7 +40,7 @@ with_changelog_in_features = lambda do |&block| end desc "Push docs/cukes to relishapp using the relish-client-gem" -task :relish, :version do |t, args| +task :relish, :version do |_t, args| raise "rake relish[VERSION]" unless args[:version] with_changelog_in_features.call do diff --git a/benchmarks/allocations/1_object_1000_mocks.rb b/benchmarks/allocations/1_object_1000_mocks.rb index 27c0ab60d..7c627d9b8 100644 --- a/benchmarks/allocations/1_object_1000_mocks.rb +++ b/benchmarks/allocations/1_object_1000_mocks.rb @@ -1,5 +1,5 @@ require_relative "helper" -symbols = (1..1000).map {|x| :"#{x}"} +symbols = (1..1000).map { |x| :"#{x}" } benchmark_allocations do o = Object.new diff --git a/benchmarks/allocations/helper.rb b/benchmarks/allocations/helper.rb index db00a8d17..a840452dd 100644 --- a/benchmarks/allocations/helper.rb +++ b/benchmarks/allocations/helper.rb @@ -3,7 +3,7 @@ require 'rspec/mocks/standalone' def benchmark_allocations(burn: 1) - stats = AllocationStats.new(burn: burn).trace do + stats = AllocationStats.new(:burn => burn).trace do yield end @@ -13,5 +13,5 @@ def benchmark_allocations(burn: 1) [:class_plus] end - puts stats.allocations(alias_paths: true).group_by(*columns).from_pwd.sort_by_size.to_text + puts stats.allocations(:alias_paths => true).group_by(*columns).from_pwd.sort_by_size.to_text end diff --git a/benchmarks/each_value_v_values_each.rb b/benchmarks/each_value_v_values_each.rb index cff19fd9a..450e5d062 100644 --- a/benchmarks/each_value_v_values_each.rb +++ b/benchmarks/each_value_v_values_each.rb @@ -1,8 +1,8 @@ require 'benchmark' -n = 10000 +n = 10_000 -m = 1.upto(1000).reduce({}) {|m, i| m[i] = i; m} +m = 1.upto(1000).inject({}) { |m, i| m[i] = i; m } Benchmark.benchmark do |bm| puts "#{n} times - ruby #{RUBY_VERSION}" @@ -13,7 +13,7 @@ 3.times do bm.report do n.times do - m.each_value {|v|} + m.each_value {} end end end @@ -24,7 +24,7 @@ 3.times do bm.report do n.times do - m.values.each{|v|} + m.values.each {} end end end @@ -43,7 +43,6 @@ # 0.910000 0.010000 0.920000 ( 0.909319) # 0.910000 0.000000 0.910000 ( 0.911225) - # $ ruby benchmarks/values_each_v_each_value.rb # 10000 times - ruby 2.0.0 # diff --git a/benchmarks/find_original_method_early.rb b/benchmarks/find_original_method_early.rb index 875ea9d02..5914dafa2 100644 --- a/benchmarks/find_original_method_early.rb +++ b/benchmarks/find_original_method_early.rb @@ -14,7 +14,7 @@ require 'benchmark' -n = 10000 +n = 10_000 Foo = Class.new(Object) do n.times do |i| diff --git a/benchmarks/method_defined_at_any_visibility.rb b/benchmarks/method_defined_at_any_visibility.rb index d538c2076..64e6e2af1 100644 --- a/benchmarks/method_defined_at_any_visibility.rb +++ b/benchmarks/method_defined_at_any_visibility.rb @@ -4,10 +4,10 @@ Foo = Class.new do 1.upto(n) do |i| - define_method(:"public_method_#{i}") { } - define_method(:"protected_method_#{i}") { } + define_method(:"public_method_#{i}") {} + define_method(:"protected_method_#{i}") {} protected :"protected_method_#{i}" - define_method(:"private_method_#{i}") { } + define_method(:"private_method_#{i}") {} private :"protected_method_#{i}" end end diff --git a/benchmarks/thread_safety.rb b/benchmarks/thread_safety.rb index 6ab24274d..e895fd8f1 100644 --- a/benchmarks/thread_safety.rb +++ b/benchmarks/thread_safety.rb @@ -7,7 +7,7 @@ bm.report("fetching a proxy") do RSpec::Mocks.with_temporary_scope do o = Object.new - 100000.times { + 100_000.times { RSpec::Mocks.space.proxy_for(o) } end diff --git a/benchmarks/transfer_nested_constants.rb b/benchmarks/transfer_nested_constants.rb index e46d42de3..3cfbf7384 100644 --- a/benchmarks/transfer_nested_constants.rb +++ b/benchmarks/transfer_nested_constants.rb @@ -3,7 +3,7 @@ require 'benchmark' require 'rspec/mocks' -N = ENV.fetch('N', 10000).to_i +N = ENV.fetch('N', 10_000).to_i M = ENV.fetch('M', 5).to_i puts "#{N} times, #{M} constants - ruby #{RUBY_VERSION}" diff --git a/features/step_definitions/additional_cli_steps.rb b/features/step_definitions/additional_cli_steps.rb index d9f3f7093..d5edc0a9f 100644 --- a/features/step_definitions/additional_cli_steps.rb +++ b/features/step_definitions/additional_cli_steps.rb @@ -1,10 +1,10 @@ Then /^the example(?:s)? should(?: all)? pass$/ do - step %q{the output should contain "0 failures"} - step %q{the exit status should be 0} + step %q(the output should contain "0 failures") + step %q(the exit status should be 0) end Then /^the examples should all fail, producing the following output:$/ do |table| - step %q{the exit status should be 1} + step %q(the exit status should be 1) examples, failures = all_output.match(/(\d+) examples?, (\d+) failures?/).captures.map(&:to_i) expect(examples).to be > 0 @@ -15,7 +15,7 @@ end Then /^it should fail with the following output:$/ do |table| - step %q{the exit status should be 1} + step %q(the exit status should be 1) lines = table.raw.flatten.reject(&:empty?) expect(all_output).to include(*lines) end diff --git a/features/support/env.rb b/features/support/env.rb index 21420d497..74a5e9517 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -10,13 +10,13 @@ end Aruba.configure do |config| - config.before_cmd do |cmd| + config.before_cmd do set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived end end if RUBY_PLATFORM == 'java' Aruba.configure do |config| - config.before_cmd do |cmd| + config.before_cmd do set_env('RBXOPT', "-Xint=true #{ENV['RBXOPT']}") # disable JIT since these processes are so short lived end end if defined?(Rubinius) diff --git a/features/support/rubinius.rb b/features/support/rubinius.rb index 390796252..fc7fab2f9 100644 --- a/features/support/rubinius.rb +++ b/features/support/rubinius.rb @@ -1,6 +1,6 @@ # Required until https://github.com/rubinius/rubinius/issues/2430 is resolved ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc" -Around "@unsupported-on-rbx" do |scenario, block| +Around "@unsupported-on-rbx" do |_scenario, block| block.call unless defined?(Rubinius) end diff --git a/spec/rspec/mocks/and_call_original_spec.rb b/spec/rspec/mocks/and_call_original_spec.rb index fdc0b2a5b..b0a01c8ff 100644 --- a/spec/rspec/mocks/and_call_original_spec.rb +++ b/spec/rspec/mocks/and_call_original_spec.rb @@ -101,7 +101,7 @@ def inst.foo; :bar; end expect(sub_sub_klass.foo).to eq(:bar) end - it "finds the method on the most direct ancestor even if the method " + + it "finds the method on the most direct ancestor even if the method " \ "is available on more distant ancestors" do klass.extend Module.new { def foo; :klass_bar; end } sub_klass = Class.new(klass) @@ -110,7 +110,7 @@ def inst.foo; :bar; end expect(sub_klass.foo).to eq(:sub_klass_bar) end - it "finds the method on the most direct singleton class ancestors even if the method " + + it "finds the method on the most direct singleton class ancestors even if the method " \ "is available on more distant ancestors" do klass.extend Module.new { def foo; :klass_bar; end } sub_klass = Class.new(klass) { def self.foo; :sub_klass_bar; end } diff --git a/spec/rspec/mocks/and_wrap_original_spec.rb b/spec/rspec/mocks/and_wrap_original_spec.rb index cf6d96ece..a69e3b4e9 100644 --- a/spec/rspec/mocks/and_wrap_original_spec.rb +++ b/spec/rspec/mocks/and_wrap_original_spec.rb @@ -57,7 +57,7 @@ def results it "can be constrained by specific arguments" do allow_it.to receive(:results) { :all } allow_it.to receive(:results).with(5).and_wrap_original { |m, n| m.call.first(n) } - expect(instance.results 5).to eq [1,2,3,4,5] + expect(instance.results 5).to eq [1, 2, 3, 4, 5] expect(instance.results).to eq :all end end diff --git a/spec/rspec/mocks/and_yield_spec.rb b/spec/rspec/mocks/and_yield_spec.rb index f902b3ee9..75cc4a979 100644 --- a/spec/rspec/mocks/and_yield_spec.rb +++ b/spec/rspec/mocks/and_yield_spec.rb @@ -20,7 +20,7 @@ it "evaluates the supplied block as it is read" do evaluated = false - allow(obj).to receive(:method_that_accepts_a_block).and_yield do |eval_context| + allow(obj).to receive(:method_that_accepts_a_block).and_yield do |_eval_context| evaluated = true end expect(evaluated).to be_truthy @@ -145,17 +145,15 @@ expect(yielded_arg).to receive(:bar) end - obj.method_that_accepts_a_block do |obj| - # obj.bar is not called here + obj.method_that_accepts_a_block do |_obj| + # _obj.bar is not called here # foo is not called here end expect { verify configured_eval_context }.to fail expect { verify yielded_arg }.to fail end - end - end end end diff --git a/spec/rspec/mocks/any_instance_spec.rb b/spec/rspec/mocks/any_instance_spec.rb index b53c805f2..d9eb1cd1c 100644 --- a/spec/rspec/mocks/any_instance_spec.rb +++ b/spec/rspec/mocks/any_instance_spec.rb @@ -3,18 +3,18 @@ module RSpec module Mocks RSpec.describe "#any_instance" do - class CustomErrorForAnyInstanceSpec < StandardError;end + class CustomErrorForAnyInstanceSpec < StandardError; end let(:klass) do Class.new do def existing_method; :existing_method_return_value; end - def existing_method_with_arguments(arg_one, arg_two = nil); :existing_method_with_arguments_return_value; end + def existing_method_with_arguments(_a, _b=nil); :existing_method_with_arguments_return_value; end def another_existing_method; end - private + private def private_method; :private_method_return_value; end end end - let(:existing_method_return_value){ :existing_method_return_value } + let(:existing_method_return_value) { :existing_method_return_value } context "invocation order" do context "when stubbing" do @@ -310,13 +310,13 @@ def private_method; :private_method_return_value; end it "works with the non-standard constructor module" do allow_any_instance_of(Module).to receive(:foo).and_return(1) - module RSpec::SampleRspecTestModule;end + module RSpec::SampleRspecTestModule; end expect(RSpec::SampleRspecTestModule.foo).to eq(1) end it "works with the non-standard constructor class" do allow_any_instance_of(Class).to receive(:foo).and_return(1) - class RSpec::SampleRspecTestClass;end + class RSpec::SampleRspecTestClass; end expect(RSpec::SampleRspecTestClass.foo).to eq(1) end end @@ -1170,7 +1170,7 @@ def call(*args) it "doesn't fail when dup accepts parameters" do klazz = Class.new do - def dup(funky_option) + def dup(_) end end diff --git a/spec/rspec/mocks/argument_matchers_spec.rb b/spec/rspec/mocks/argument_matchers_spec.rb index f4f76fae7..3d4c15499 100644 --- a/spec/rspec/mocks/argument_matchers_spec.rb +++ b/spec/rspec/mocks/argument_matchers_spec.rb @@ -283,14 +283,14 @@ module Mocks it "fails array_including when args aren't array", :reset => true do expect(a_double).to receive(:msg).with(array_including(1, 2, 3)) expect { - a_double.msg(1, 2, 3) + a_double.msg(1, 2, 3) }.to fail_including "expected: (array_including(1, 2, 3))" end it "fails array_including when arg doesn't contain all elements", :reset => true do expect(a_double).to receive(:msg).with(array_including(1, 2, 3)) expect { - a_double.msg([1, 2]) + a_double.msg([1, 2]) }.to fail_including "expected: (array_including(1, 2, 3))" end end @@ -429,7 +429,7 @@ def ==(other) it "fails with zero arguments", :reset => true do expect do - expect(a_double).to receive(:msg).with {|arg| expect(arg).to eq :received } + expect(a_double).to receive(:msg).with { |arg| expect(arg).to eq :received } end.to raise_error(ArgumentError, /must have at least one argument/) end diff --git a/spec/rspec/mocks/array_including_matcher_spec.rb b/spec/rspec/mocks/array_including_matcher_spec.rb index 1430f0391..f9a4495cf 100644 --- a/spec/rspec/mocks/array_including_matcher_spec.rb +++ b/spec/rspec/mocks/array_including_matcher_spec.rb @@ -43,7 +43,7 @@ module ArgumentMatchers context "failing" do it "fails when not all the entries in the expected are present" do - expect(array_including(1,2,3,4,5)).not_to be === [1,2] + expect(array_including(1, 2, 3, 4, 5)).not_to be === [1, 2] end it "fails when passed a composed matcher is pased and not satisfied" do diff --git a/spec/rspec/mocks/block_return_value_spec.rb b/spec/rspec/mocks/block_return_value_spec.rb index 5a16ca143..121fb2cc8 100644 --- a/spec/rspec/mocks/block_return_value_spec.rb +++ b/spec/rspec/mocks/block_return_value_spec.rb @@ -27,7 +27,7 @@ it 'forwards all given args to the block, even when it receives a block' do obj = Object.new yielded_args = [] - allow(obj).to receive(:foo) { |*args, &bl| yielded_args << args } + allow(obj).to receive(:foo) { |*args, &_| yielded_args << args } obj.foo(1, 2, 3) expect(yielded_args).to eq([[1, 2, 3]]) @@ -43,7 +43,7 @@ it "returns the value of executing the block with given argument" do obj = Object.new - allow(obj).to receive(:foo).with('baz') {|x| 'bar' + x } + allow(obj).to receive(:foo).with('baz') { |x| 'bar' + x } expect(obj.foo('baz')).to eq('barbaz') end end diff --git a/spec/rspec/mocks/combining_implementation_instructions_spec.rb b/spec/rspec/mocks/combining_implementation_instructions_spec.rb index 3a9b0cba8..27d37cb9d 100644 --- a/spec/rspec/mocks/combining_implementation_instructions_spec.rb +++ b/spec/rspec/mocks/combining_implementation_instructions_spec.rb @@ -72,7 +72,7 @@ def verify_combined_implementation expect(dbl).to receive(:foo).twice { @block_called = true } end - the_double.foo { |a| } # to ensure it is called twice + the_double.foo { |_| } # to ensure it is called twice end it 'works when passing a block to `ordered`' do @@ -166,7 +166,7 @@ def verify_combined_implementation expect(RSpec).not_to receive(:warning) obj = Object.new - stub = allow(obj).to receive(:foo) { } + stub = allow(obj).to receive(:foo) {} stub.with(1) end @@ -191,7 +191,7 @@ def verify_combined_implementation expect { stubbed.and_raise("a") }.to raise_error(msg_fragment) expect { stubbed.and_throw(:bar) }.to raise_error(msg_fragment) - expect { stubbed.once { } }.to raise_error(msg_fragment) + expect { stubbed.once {} }.to raise_error(msg_fragment) expect(dbl.size).to eq(3) end diff --git a/spec/rspec/mocks/configuration_spec.rb b/spec/rspec/mocks/configuration_spec.rb index 4308b1220..dd1a00f7a 100644 --- a/spec/rspec/mocks/configuration_spec.rb +++ b/spec/rspec/mocks/configuration_spec.rb @@ -5,7 +5,7 @@ module Mocks let(:mod_1) { Module.new } let(:mod_2) { Module.new } - def instance_methods_of(mod) + def instance_methods_of(_mod) mod_1.instance_methods.map(&:to_sym) end diff --git a/spec/rspec/mocks/diffing_spec.rb b/spec/rspec/mocks/diffing_spec.rb index 23c8d054e..70f985fd7 100644 --- a/spec/rspec/mocks/diffing_spec.rb +++ b/spec/rspec/mocks/diffing_spec.rb @@ -33,7 +33,9 @@ expect(d).to receive(:foo).with("some string\nline2") expect { d.foo("this other string") - }.to fail_with("# received :foo with unexpected arguments\n expected: (\"some string\\nline2\")\n got: (\"this other string\")\nDiff:\n@@ -1,3 +1,2 @@\n-some string\n-line2\n+this other string\n") + }.to fail_with("# received :foo with unexpected arguments\n" \ + " expected: (\"some string\\nline2\")\n got: (\"this other string\")\n" \ + "Diff:\n@@ -1,3 +1,2 @@\n-some string\n-line2\n+this other string\n") end end @@ -42,7 +44,9 @@ expect(d).to receive(:foo).with("some string\nline2", "some other string") expect { d.foo("this other string") - }.to fail_with("# received :foo with unexpected arguments\n expected: (\"some string\\nline2\", \"some other string\")\n got: (\"this other string\")\nDiff:\n@@ -1,3 +1,2 @@\n-some string\\nline2\n-some other string\n+this other string\n") + }.to fail_with("# received :foo with unexpected arguments\n" \ + " expected: (\"some string\\nline2\", \"some other string\")\n" \ + " got: (\"this other string\")\nDiff:\n@@ -1,3 +1,2 @@\n-some string\\nline2\n-some other string\n+this other string\n") end end @@ -84,7 +88,7 @@ # has occasionally failed due to the output ordering varying between `inspect` # calls to the same hash. This regex allows us to work around that. def hash_regex_inspect(hash) - "\\{(#{hash.map { |key,value| "#{key.inspect}=>#{value.inspect}.*" }.join "|"}){#{hash.size}}\\}" + "\\{(#{hash.map { |key, value| "#{key.inspect}=>#{value.inspect}.*" }.join "|"}){#{hash.size}}\\}" end else def hash_regex_inspect(hash) @@ -111,7 +115,9 @@ def hash_regex_inspect(hash) expect(d).to receive(:foo).with(collab) expect { d.foo([]) - }.to fail_with("# received :foo with unexpected arguments\n expected: (#{collab_inspect})\n got: ([])\nDiff:\n@@ -1,2 +1,2 @@\n-[#{collab_inspect}]\n+[[]]\n") + }.to fail_with("# received :foo with unexpected arguments\n" \ + " expected: (#{collab_inspect})\n" \ + " got: ([])\nDiff:\n@@ -1,2 +1,2 @@\n-[#{collab_inspect}]\n+[[]]\n") end end end @@ -128,7 +134,9 @@ def hash_regex_inspect(hash) expect(d).to receive(:foo).with(collab) expect { d.foo([:a, :b]) - }.to fail_with("# received :foo with unexpected arguments\n expected: (#{collab_description})\n got: ([:a, :b])\nDiff:\n@@ -1,2 +1,2 @@\n-[\"#{collab_description}\"]\n+[[:a, :b]]\n") + }.to fail_with("# received :foo with unexpected arguments\n" \ + " expected: (#{collab_description})\n" \ + " got: ([:a, :b])\nDiff:\n@@ -1,2 +1,2 @@\n-[\"#{collab_description}\"]\n+[[:a, :b]]\n") end end end @@ -154,7 +162,9 @@ def inspect expect(d).to receive(:foo).with(collab) expect { d.foo([:a, :b]) - }.to fail_with("# received :foo with unexpected arguments\n expected: (#{collab_inspect})\n got: ([:a, :b])\nDiff:\n@@ -1,2 +1,2 @@\n-[#{collab_pp}]\n+[[:a, :b]]\n") + }.to fail_with("# received :foo with unexpected arguments\n" \ + " expected: (#{collab_inspect})\n" \ + " got: ([:a, :b])\nDiff:\n@@ -1,2 +1,2 @@\n-[#{collab_pp}]\n+[[:a, :b]]\n") end end end diff --git a/spec/rspec/mocks/double_spec.rb b/spec/rspec/mocks/double_spec.rb index 86d049853..ee4629c0a 100644 --- a/spec/rspec/mocks/double_spec.rb +++ b/spec/rspec/mocks/double_spec.rb @@ -195,63 +195,63 @@ module Mocks end it "allows parameter as return value" do - expect(@double).to receive(:something).with("a","b","c").and_return("booh") - expect(@double.something("a","b","c")).to eq "booh" + expect(@double).to receive(:something).with("a", "b", "c").and_return("booh") + expect(@double.something("a", "b", "c")).to eq "booh" verify @double end it "returns the previously stubbed value if no return value is set" do - allow(@double).to receive(:something).with("a","b","c").and_return(:stubbed_value) - expect(@double).to receive(:something).with("a","b","c") - expect(@double.something("a","b","c")).to eq :stubbed_value + allow(@double).to receive(:something).with("a", "b", "c").and_return(:stubbed_value) + expect(@double).to receive(:something).with("a", "b", "c") + expect(@double.something("a", "b", "c")).to eq :stubbed_value verify @double end it "returns nil if no return value is set and there is no previously stubbed value" do - expect(@double).to receive(:something).with("a","b","c") - expect(@double.something("a","b","c")).to be_nil + expect(@double).to receive(:something).with("a", "b", "c") + expect(@double.something("a", "b", "c")).to be_nil verify @double end it "raises exception if args don't match when method called" do - expect(@double).to receive(:something).with("a","b","c").and_return("booh") + expect(@double).to receive(:something).with("a", "b", "c").and_return("booh") expect { - @double.something("a","d","c") + @double.something("a", "d", "c") }.to fail_with "# received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")" end describe "even when a similar expectation with different arguments exist" do it "raises exception if args don't match when method called, correctly reporting the offending arguments" do - expect(@double).to receive(:something).with("a","b","c").once - expect(@double).to receive(:something).with("z","x","c").once + expect(@double).to receive(:something).with("a", "b", "c").once + expect(@double).to receive(:something).with("z", "x", "c").once expect { - @double.something("a","b","c") - @double.something("z","x","g") + @double.something("a", "b", "c") + @double.something("z", "x", "g") }.to fail_with "# received :something with unexpected arguments\n expected: (\"z\", \"x\", \"c\")\n got: (\"z\", \"x\", \"g\")" end end it "raises exception if args don't match when method called even when the method is stubbed" do allow(@double).to receive(:something) - expect(@double).to receive(:something).with("a","b","c") + expect(@double).to receive(:something).with("a", "b", "c") expect { - @double.something("a","d","c") + @double.something("a", "d", "c") verify @double }.to fail_with "# received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")" end it "raises exception if args don't match when method called even when using null_object" do @double = double("test double").as_null_object - expect(@double).to receive(:something).with("a","b","c") + expect(@double).to receive(:something).with("a", "b", "c") expect { - @double.something("a","d","c") + @double.something("a", "d", "c") verify @double }.to fail_with "# received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")" end describe 'with a method that has a default argument' do it "raises an exception if the arguments don't match when the method is called, correctly reporting the offending arguments" do - def @double.method_with_default_argument(arg={}); end + def @double.method_with_default_argument(_={}); end expect(@double).to receive(:method_with_default_argument).with({}) expect { @@ -263,7 +263,7 @@ def @double.method_with_default_argument(arg={}); end it "fails if unexpected method called" do expect { - @double.something("a","b","c") + @double.something("a", "b", "c") }.to fail_with "# received unexpected message :something with (\"a\", \"b\", \"c\")" end @@ -289,13 +289,13 @@ def @double.method_with_default_argument(arg={}); end it "is wrappable in an array" do with_isolated_stderr do - expect( Array(@double) ).to eq([@double]) + expect(Array(@double)).to eq([@double]) end end it "is wrappable in an array when a null object" do with_isolated_stderr do - expect( Array(@double.as_null_object) ).to eq [@double] + expect(Array(@double.as_null_object)).to eq [@double] end end @@ -319,7 +319,7 @@ def @double.method_with_default_argument(arg={}); end end it "passes proc to expectation block with an argument" do - expect(@double).to receive(:foo) { |arg, &block| expect(block.call).to eq(:bar) } + expect(@double).to receive(:foo) { |_, &block| expect(block.call).to eq(:bar) } @double.foo(:arg) { :bar } end @@ -329,7 +329,7 @@ def @double.method_with_default_argument(arg={}); end end it "passes proc to stub block with an argument" do - allow(@double).to receive(:foo) { |arg, &block| expect(block.call).to eq(:bar) } + allow(@double).to receive(:foo) { |_, &block| expect(block.call).to eq(:bar) } @double.foo(:arg) { :bar } end @@ -407,7 +407,7 @@ def initialize(amount, units) end it "fails on no args if any args received" do - expect(@double).to receive(:something).with(no_args()) + expect(@double).to receive(:something).with(no_args) expect { @double.something 1 }.to fail_with "# received :something with unexpected arguments\n expected: (no args)\n got: (1)" @@ -428,99 +428,99 @@ def initialize(amount, units) end it "yields 0 args to blocks that take a variable number of arguments" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield + expect(@double).to receive(:yield_back).with(no_args).once.and_yield a = nil - @double.yield_back {|*x| a = x} + @double.yield_back { |*x| a = x } expect(a).to eq [] verify @double end it "yields 0 args multiple times to blocks that take a variable number of arguments" do - expect(@double).to receive(:yield_back).once.with(no_args()).once.and_yield. + expect(@double).to receive(:yield_back).once.with(no_args).once.and_yield. and_yield b = [] - @double.yield_back {|*a| b << a} - expect(b).to eq [ [], [] ] + @double.yield_back { |*a| b << a } + expect(b).to eq [[], []] verify @double end it "yields one arg to blocks that take a variable number of arguments" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield(99) + expect(@double).to receive(:yield_back).with(no_args).once.and_yield(99) a = nil - @double.yield_back {|*x| a = x} + @double.yield_back { |*x| a = x } expect(a).to eq [99] verify @double end it "yields one arg 3 times consecutively to blocks that take a variable number of arguments" do - expect(@double).to receive(:yield_back).once.with(no_args()).once.and_yield(99). + expect(@double).to receive(:yield_back).once.with(no_args).once.and_yield(99). and_yield(43). and_yield("something fruity") b = [] - @double.yield_back {|*a| b << a} + @double.yield_back { |*a| b << a } expect(b).to eq [[99], [43], ["something fruity"]] verify @double end it "yields many args to blocks that take a variable number of arguments" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go") + expect(@double).to receive(:yield_back).with(no_args).once.and_yield(99, 27, "go") a = nil - @double.yield_back {|*x| a = x} + @double.yield_back { |*x| a = x } expect(a).to eq [99, 27, "go"] verify @double end it "yields many args 3 times consecutively to blocks that take a variable number of arguments" do - expect(@double).to receive(:yield_back).once.with(no_args()).once.and_yield(99, :green, "go"). + expect(@double).to receive(:yield_back).once.with(no_args).once.and_yield(99, :green, "go"). and_yield("wait", :amber). and_yield("stop", 12, :red) b = [] - @double.yield_back {|*a| b << a} + @double.yield_back { |*a| b << a } expect(b).to eq [[99, :green, "go"], ["wait", :amber], ["stop", 12, :red]] verify @double end it "yields single value" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield(99) + expect(@double).to receive(:yield_back).with(no_args).once.and_yield(99) a = nil - @double.yield_back {|x| a = x} + @double.yield_back { |x| a = x } expect(a).to eq 99 verify @double end it "yields single value 3 times consecutively" do - expect(@double).to receive(:yield_back).once.with(no_args()).once.and_yield(99). + expect(@double).to receive(:yield_back).once.with(no_args).once.and_yield(99). and_yield(43). and_yield("something fruity") b = [] - @double.yield_back {|a| b << a} + @double.yield_back { |a| b << a } expect(b).to eq [99, 43, "something fruity"] verify @double end it "yields two values" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup') + expect(@double).to receive(:yield_back).with(no_args).once.and_yield('wha', 'zup') a, b = nil - @double.yield_back {|x,y| a=x; b=y} + @double.yield_back { |x, y| a = x; b = y } expect(a).to eq 'wha' expect(b).to eq 'zup' verify @double end it "yields two values 3 times consecutively" do - expect(@double).to receive(:yield_back).once.with(no_args()).once.and_yield('wha', 'zup'). + expect(@double).to receive(:yield_back).once.with(no_args).once.and_yield('wha', 'zup'). and_yield('not', 'down'). and_yield(14, 65) c = [] - @double.yield_back {|a,b| c << [a, b]} - expect(c).to eq [['wha', 'zup'], ['not', 'down'], [14, 65]] + @double.yield_back { |a, b| c << [a, b] } + expect(c).to eq [%w[wha zup], %w[not down], [14, 65]] verify @double end it "fails when calling yielding method with wrong arity" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup') + expect(@double).to receive(:yield_back).with(no_args).once.and_yield('wha', 'zup') expect { - @double.yield_back {|a|} + @double.yield_back { |_| } }.to fail_with "# yielded |\"wha\", \"zup\"| to block with arity of 1" end @@ -534,17 +534,17 @@ def initialize(amount, units) end it "fails when calling yielding method consecutively with wrong arity" do - expect(@double).to receive(:yield_back).once.with(no_args()).and_yield('wha', 'zup'). + expect(@double).to receive(:yield_back).once.with(no_args).and_yield('wha', 'zup'). and_yield('down'). and_yield(14, 65) expect { c = [] - @double.yield_back {|a,b| c << [a, b]} + @double.yield_back { |a, b| c << [a, b] } }.to fail_with "# yielded |\"down\"| to block with arity of 2" end it "fails when calling yielding method without block" do - expect(@double).to receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup') + expect(@double).to receive(:yield_back).with(no_args).once.and_yield('wha', 'zup') expect { @double.yield_back }.to fail_with "# asked to yield |[\"wha\", \"zup\"]| but no block was passed" @@ -560,7 +560,7 @@ def initialize(amount, units) expect(@double).to receive(:yield_me).and_yield 44 expect { - @double.yield_me do |x| + @double.yield_me do |_| raise "Bang" end }.to raise_error(StandardError, "Bang") @@ -578,10 +578,10 @@ def initialize(amount, units) end it "restores objects to their original state on rspec_reset" do - double = double("this is a double") - expect(double).to receive(:blah) - reset double - verify double #should throw if reset didn't work + dbl = double("this is a double") + expect(dbl).to receive(:blah) + reset dbl + verify dbl # should throw if reset didn't work end it "temporarily replaces a method stub on a double" do @@ -635,8 +635,8 @@ def initialize(amount, units) it "does not mess with the stub's yielded values when also doubleed" do allow(@double).to receive(:yield_back).and_yield(:stub_value) expect(@double).to receive(:yield_back).and_yield(:double_value) - @double.yield_back{|v| expect(v).to eq :double_value } - @double.yield_back{|v| expect(v).to eq :stub_value } + @double.yield_back { |v| expect(v).to eq :double_value } + @double.yield_back { |v| expect(v).to eq :stub_value } verify @double end @@ -651,8 +651,8 @@ def initialize(amount, units) end it "assigns stub return values" do - double = RSpec::Mocks::Double.new('name', :message => :response) - expect(double.message).to eq :response + dbl = RSpec::Mocks::Double.new('name', :message => :response) + expect(dbl.message).to eq :response end describe "a double message receiving a block" do @@ -662,7 +662,7 @@ def initialize(amount, units) end def add_call - @calls = @calls + 1 + @calls += 1 end it "supports a block passed to `receive` for `expect`" do @@ -720,16 +720,16 @@ def add_call describe 'string representation generated by #to_s' do it 'does not contain < because that might lead to invalid HTML in some situations' do - double = double("Dog") - valid_html_str = "#{double}" + dbl = double("Dog") + valid_html_str = "#{dbl}" expect(valid_html_str).not_to include('<') end end describe "#to_str", :unless => RUBY_VERSION == '1.9.2' do it "should not respond to #to_str to avoid being coerced to strings by the runtime" do - double = double("Foo") - expect { double.to_str }.to raise_error( + dbl = double("Foo") + expect { dbl.to_str }.to raise_error( RSpec::Mocks::MockExpectationError, '# received unexpected message :to_str with (no args)') end @@ -737,14 +737,14 @@ def add_call describe "double created with no name" do it "does not use a name in a failure message" do - double = double() - expect {double.foo}.to raise_error.with_message(a_string_including("# received")) + dbl = double + expect { dbl.foo }.to raise_error.with_message(a_string_including("# received")) end it "does respond to initially stubbed methods" do - double = double(:foo => "woo", :bar => "car") - expect(double.foo).to eq "woo" - expect(double.bar).to eq "car" + dbl = double(:foo => "woo", :bar => "car") + expect(dbl.foo).to eq "woo" + expect(dbl.bar).to eq "car" end end diff --git a/spec/rspec/mocks/example_methods_spec.rb b/spec/rspec/mocks/example_methods_spec.rb index 59c526524..36bb71623 100644 --- a/spec/rspec/mocks/example_methods_spec.rb +++ b/spec/rspec/mocks/example_methods_spec.rb @@ -1,8 +1,8 @@ module RSpec module Mocks RSpec.describe ExampleMethods do - it 'does not define private helper methods since it gets included into a ' + - 'namespace where users define methods and could inadvertently overwrite ' + + it 'does not define private helper methods since it gets included into a ' \ + 'namespace where users define methods and could inadvertently overwrite ' \ 'them' do expect(ExampleMethods.private_instance_methods).to eq([]) end diff --git a/spec/rspec/mocks/matchers/have_received_spec.rb b/spec/rspec/mocks/matchers/have_received_spec.rb index cbeeff4fc..a75bcd95a 100644 --- a/spec/rspec/mocks/matchers/have_received_spec.rb +++ b/spec/rspec/mocks/matchers/have_received_spec.rb @@ -84,7 +84,7 @@ module Mocks expect(dbl).to have_received(:foo) { |*args| yielded << args } - _expect(yielded).to include([:a,:b,:c]) + _expect(yielded).to include([:a, :b, :c]) end it "takes a do-end block and yields the arguments given to the stubbed method call" do @@ -94,7 +94,7 @@ module Mocks expect(dbl).to have_received(:foo) do |*args| yielded << args end - _expect(yielded).to include([:a,:b,:c]) + _expect(yielded).to include([:a, :b, :c]) end it "passes if expectations against the yielded arguments pass" do @@ -117,7 +117,7 @@ module Mocks }.to raise_error(RSpec::Expectations::ExpectationNotMetError) end - it 'gives precedence to a `{ ... }` block when both forms are provided ' + + it 'gives precedence to a `{ ... }` block when both forms are provided ' \ 'since that form actually binds to `receive`' do dbl = double(:foo => nil) called = [] @@ -131,7 +131,7 @@ module Mocks it 'forwards any block passed during method invocation to the `have_received` block' do dbl = spy - block = lambda { } + block = lambda {} dbl.foo(&block) expect(dbl).to have_received(:foo) do |&passed_block| @@ -242,7 +242,7 @@ module Mocks _expect { expect(dbl).to have_received(:expected_method).with(:four, :four).once }.to fail_including("expected: (:four, :four)", - "got:","(:one, :four) (2 times)", + "got:", "(:one, :four) (2 times)", "(:two, :four) (1 time)", "(:three, :four) (3 times)") end @@ -264,7 +264,7 @@ module Mocks _expect { expect(dbl).to have_received(:expected_method).with(:one, :four).once }.to fail_including("expected: (:one, :four)", - "got:","([:one], :four)", + "got:", "([:one], :four)", "(:one, [:four])") end @@ -274,7 +274,7 @@ module Mocks _expect { expect(dbl).to have_received(:expected_method).with(:one, :two, :three).once - }.to fail_including("expected: (:one, :two, :three)", "got:","(:one, :one, :two)") + }.to fail_including("expected: (:one, :two, :three)", "got:", "(:one, :one, :two)") end end end @@ -601,7 +601,7 @@ module Mocks end end - %w(exactly at_least at_most times once twice).each do |constraint| + %w[exactly at_least at_most times once twice].each do |constraint| it "does not allow #{constraint} to be used because it creates confusion" do dbl = double_with_unmet_expectation(:expected_method) _expect { diff --git a/spec/rspec/mocks/matchers/receive_messages_spec.rb b/spec/rspec/mocks/matchers/receive_messages_spec.rb index 4c6e729e8..c6ea801f2 100644 --- a/spec/rspec/mocks/matchers/receive_messages_spec.rb +++ b/spec/rspec/mocks/matchers/receive_messages_spec.rb @@ -124,28 +124,28 @@ module Mocks example "allow(...).to_not receive_messages(:a => 1, :b => 2)" do expect { allow(obj).to_not receive_messages(:a => 1, :b => 2) }.to( - raise_error "`allow(...).to_not receive_messages` is not supported "+ + raise_error "`allow(...).to_not receive_messages` is not supported " \ "since it doesn't really make sense. What would it even mean?" ) end example "allow_any_instance_of(...).to_not receive_messages(:a => 1, :b => 2)" do expect { allow_any_instance_of(obj).to_not receive_messages(:a => 1, :b => 2) }.to( - raise_error "`allow_any_instance_of(...).to_not receive_messages` is not supported "+ + raise_error "`allow_any_instance_of(...).to_not receive_messages` is not supported " \ "since it doesn't really make sense. What would it even mean?" ) end example "expect(...).to_not receive_messages(:a => 1, :b => 2)" do expect { expect(obj).to_not receive_messages(:a => 1, :b => 2) }.to( - raise_error "`expect(...).to_not receive_messages` is not supported "+ + raise_error "`expect(...).to_not receive_messages` is not supported " \ "since it doesn't really make sense. What would it even mean?" ) end example "expect_any_instance_of(...).to_not receive_messages(:a => 1, :b => 2)" do expect { expect_any_instance_of(obj).to_not receive_messages(:a => 1, :b => 2) }.to( - raise_error "`expect_any_instance_of(...).to_not receive_messages` is not supported "+ + raise_error "`expect_any_instance_of(...).to_not receive_messages` is not supported " \ "since it doesn't really make sense. What would it even mean?" ) end diff --git a/spec/rspec/mocks/matchers/receive_spec.rb b/spec/rspec/mocks/matchers/receive_spec.rb index bedd70b38..d0fb4a75b 100644 --- a/spec/rspec/mocks/matchers/receive_spec.rb +++ b/spec/rspec/mocks/matchers/receive_spec.rb @@ -75,7 +75,7 @@ module Mocks expect(receiver.foo).to eq(5) end - it 'gives precedence to a `{ ... }` block when both forms are provided ' + + it 'gives precedence to a `{ ... }` block when both forms are provided ' \ 'since that form actually binds to `receive`' do wrapped.to receive(:foo) { :curly } do :do_end @@ -198,7 +198,7 @@ module Mocks it 'allows the caller to constrain the received arguments' do wrapped.not_to receive(:foo).with(:a) - def receiver.method_missing(*a); end # a poor man's stub... + def receiver.method_missing(*); end # a poor man's stub... expect { receiver.foo(:b) @@ -491,7 +491,7 @@ def receiver.method_missing(*a); end # a poor man's stub... Class.new do include RSpec::Mocks::ExampleMethods - def eq(value) + def eq(_) double("MyMatcher") end end diff --git a/spec/rspec/mocks/mock_ordering_spec.rb b/spec/rspec/mocks/mock_ordering_spec.rb index d4eebb799..c0727b666 100644 --- a/spec/rspec/mocks/mock_ordering_spec.rb +++ b/spec/rspec/mocks/mock_ordering_spec.rb @@ -1,6 +1,5 @@ module RSpec module Mocks - RSpec.describe "ordering" do before { @double = double("test double") } after { reset @double } diff --git a/spec/rspec/mocks/multiple_return_value_spec.rb b/spec/rspec/mocks/multiple_return_value_spec.rb index a83ae305c..2c5737955 100644 --- a/spec/rspec/mocks/multiple_return_value_spec.rb +++ b/spec/rspec/mocks/multiple_return_value_spec.rb @@ -16,8 +16,8 @@ module Mocks RSpec.describe "a message expectation with multiple return values and no specified count" do before(:each) do @double = double - @return_values = [1,2,3] - expect(@double).to receive(:do_something).and_return(@return_values[0],@return_values[1],@return_values[2]) + @return_values = [1, 2, 3] + expect(@double).to receive(:do_something).and_return(@return_values[0], @return_values[1], @return_values[2]) end it "returns values in order" do @@ -53,7 +53,7 @@ module Mocks RSpec.describe "a message expectation with multiple return values with a specified count equal to the number of values" do before(:each) do @double = double - @return_values = [1,2,3] + @return_values = [1, 2, 3] expect(@double).to receive(:do_something).exactly(3).times.and_return(@return_values[0], @return_values[1], @return_values[2]) end diff --git a/spec/rspec/mocks/mutate_const_spec.rb b/spec/rspec/mocks/mutate_const_spec.rb index bb9bb7a29..7786dd637 100644 --- a/spec/rspec/mocks/mutate_const_spec.rb +++ b/spec/rspec/mocks/mutate_const_spec.rb @@ -152,7 +152,6 @@ def change_const_value_to(value) it_behaves_like "loaded constant hiding", "TestClassThatDefinesSend::C" end - context 'for a loaded nested constant' do it_behaves_like "loaded constant hiding", "TestClass::Nested" end @@ -206,8 +205,8 @@ def change_const_value_to(value) hide_const("TOP_LEVEL_VALUE_CONST") expect(recursive_const_defined?("TOP_LEVEL_VALUE_CONST")).to be_falsey - stub_const("TOP_LEVEL_VALUE_CONST", 12345) - expect(TOP_LEVEL_VALUE_CONST).to eq 12345 + stub_const("TOP_LEVEL_VALUE_CONST", 12_345) + expect(TOP_LEVEL_VALUE_CONST).to eq 12_345 reset_rspec_mocks expect(TOP_LEVEL_VALUE_CONST).to eq orig_value diff --git a/spec/rspec/mocks/partial_double_spec.rb b/spec/rspec/mocks/partial_double_spec.rb index 6bf979e94..9606f3a89 100644 --- a/spec/rspec/mocks/partial_double_spec.rb +++ b/spec/rspec/mocks/partial_double_spec.rb @@ -109,10 +109,10 @@ module Mocks it "uses reports nil in the error message" do allow_message_expectations_on_nil - _nil = nil - expect(_nil).to receive(:foobar) + nil_var = nil + expect(nil_var).to receive(:foobar) expect { - verify _nil + verify nil_var }.to raise_error( RSpec::Mocks::MockExpectationError, %Q|(nil).foobar(*(any args))\n expected: 1 time with any arguments\n received: 0 times with any arguments| @@ -138,15 +138,15 @@ def self.inspect expect(object).to receive(:foobar) twin = object.clone twin.foobar - expect{ verify twin }.not_to raise_error - expect{ verify object }.not_to raise_error + expect { verify twin }.not_to raise_error + expect { verify object }.not_to raise_error end it "clears message expectations when `dup`ed" do expect(object).to receive(:foobar) duplicate = object.dup - expect{ duplicate.foobar }.to raise_error(NoMethodError, /foobar/) - expect{ verify object }.to fail_with(/foobar/) + expect { duplicate.foobar }.to raise_error(NoMethodError, /foobar/) + expect { verify object }.to fail_with(/foobar/) end end @@ -249,7 +249,6 @@ def ==(other) end RSpec.describe "A partial class mock that has been subclassed" do - let(:klass) { Class.new } let(:subklass) { Class.new(klass) } @@ -284,9 +283,9 @@ def public_method private_method protected_method end - protected + protected def protected_method; end - private + private def private_method; end end end @@ -310,7 +309,6 @@ def private_method; end expect(object.protected_methods).to include_method(:protected_method) object.public_method end - end RSpec.describe 'when verify_partial_doubles configuration option is set' do @@ -322,7 +320,7 @@ def implemented "works" end - def initialize(a, b) + def initialize(_a, _b) end def respond_to?(method_name, include_all=false) @@ -337,7 +335,7 @@ def method_missing(method_name, *args) end end - private + private def defined_private_method "works" @@ -384,7 +382,7 @@ def defined_private_method end it 'avoids deadlocks when a proxy is accessed from within a `before_verifying_doubles` callback' do - _klass = Class.new { def message; end; } + msg_klass = Class.new { def message; end; } called_for = [] RSpec.configuration.mock_with(:rspec) do |config| @@ -396,7 +394,7 @@ def defined_private_method end end - expect { allow(_klass.new).to receive(:message) }.to_not raise_error + expect { allow(msg_klass.new).to receive(:message) }.to_not raise_error end context "for a class" do @@ -469,7 +467,6 @@ def defined_private_method }.to yield_with_args(have_attributes :target => klass) end - it 'does not allow a non-existing method to be called on any_instance' do prevents(/does not implement/) { expect_any_instance_of(klass).to receive(:unimplemented) @@ -519,7 +516,7 @@ def defined_private_method context "on a class that has redefined `new`" do it "uses the method signature of the redefined `new` for arg verification" do subclass = Class.new(klass) do - def self.new(a); end + def self.new(_); end end prevents(/arguments/) { allow(subclass).to receive(:new).with(1, 2) } diff --git a/spec/rspec/mocks/reraising_eager_raises_spec.rb b/spec/rspec/mocks/reraising_eager_raises_spec.rb index c69919d74..6071c7607 100644 --- a/spec/rspec/mocks/reraising_eager_raises_spec.rb +++ b/spec/rspec/mocks/reraising_eager_raises_spec.rb @@ -34,7 +34,7 @@ # Prepare a failing expectation for a different message expect(dbl).not_to receive(:bar) - RSpec::Support.with_failure_notifier(Proc.new { }) { dbl.bar } + RSpec::Support.with_failure_notifier(Proc.new {}) { dbl.bar } }.not_to notify_with_same_source_id_as_later_verification end end @@ -95,7 +95,7 @@ def prepare(dbl) end context "when an expectation is called out of order", - :pending => "Says bar was called 0 times when it was, see: http://git.io/pjTq" do + :pending => "Says bar was called 0 times when it was, see: http://git.io/pjTq" do it "reraises during verification" do with_unfulfilled_double do |dbl| expect(dbl).to receive(:foo).ordered @@ -150,7 +150,7 @@ def verify_all_source_id def capture_notified_source_id(&block) source_id = nil - notifier = Proc.new { |err, opt| source_id = opt.fetch(:source_id) } + notifier = Proc.new { |_err, opt| source_id = opt.fetch(:source_id) } RSpec::Support.with_failure_notifier(notifier, &block) source_id end diff --git a/spec/rspec/mocks/should_syntax_spec.rb b/spec/rspec/mocks/should_syntax_spec.rb index 6337b8d12..d9de00399 100644 --- a/spec/rspec/mocks/should_syntax_spec.rb +++ b/spec/rspec/mocks/should_syntax_spec.rb @@ -16,13 +16,13 @@ end it "answers true for received_message? when message received with correct args" do - dbl.message 1,2,3 - expect(dbl.received_message?(:message, 1,2,3)).to be_truthy + dbl.message 1, 2, 3 + expect(dbl.received_message?(:message, 1, 2, 3)).to be_truthy end it "answers false for received_message? when message received with incorrect args" do - dbl.message 1,2,3 - expect(dbl.received_message?(:message, 1,2)).to be_falsey + dbl.message 1, 2, 3 + expect(dbl.received_message?(:message, 1, 2)).to be_falsey end end @@ -163,7 +163,7 @@ def use_rspec_mocks verify mock rescue Exception => e ensure - expect(e.backtrace.to_s).to match(/\/path\/to\/blah.ext:37/m) + expect(e.backtrace.to_s).to match(%r{/path/to/blah.ext:37}m) end end @@ -215,9 +215,9 @@ def use_rspec_mocks let(:klass) do Class.new do def existing_method; :existing_method_return_value; end - def existing_method_with_arguments(arg_one, arg_two = nil); :existing_method_with_arguments_return_value; end + def existing_method_with_arguments(_a, _b=nil); :existing_method_with_arguments_return_value; end def another_existing_method; end - private + private def private_method; :private_method_return_value; end end end @@ -466,7 +466,7 @@ def use_rspec_mocks let(:expected_arguments) { [ /Using.*without explicitly enabling/, - {:replacement=>"the new `:expect` syntax or explicitly enable `:should`"} + {:replacement => "the new `:expect` syntax or explicitly enable `:should`"} ] } @@ -500,7 +500,7 @@ def use_rspec_mocks it "warns about unstubbing once, regardless of how many times it is called" do expect(RSpec).to receive(:deprecate).with(/Using.*without explicitly enabling/, - {:replacement => "`allow(...).to receive(...).and_call_original` or explicitly enable `:should`"}) + :replacement => "`allow(...).to receive(...).and_call_original` or explicitly enable `:should`") o = Object.new o2 = Object.new @@ -511,7 +511,6 @@ def use_rspec_mocks o2.unstub(:faces) end - it "doesn't warn about stubbing after a reset and setting should" do expect(RSpec).not_to receive(:deprecate) RSpec::Mocks.configuration.reset_syntaxes_to_default diff --git a/spec/rspec/mocks/spy_spec.rb b/spec/rspec/mocks/spy_spec.rb index 0921e506c..49ce160b6 100644 --- a/spec/rspec/mocks/spy_spec.rb +++ b/spec/rspec/mocks/spy_spec.rb @@ -33,7 +33,7 @@ end it "records called methods" do - expect(subject.tap { |s| s.foo}).to have_received(:foo) + expect(subject.tap { |s| s.foo }).to have_received(:foo) end it 'fails fast when `have_received` is passed an undefined method name' do diff --git a/spec/rspec/mocks/stash_spec.rb b/spec/rspec/mocks/stash_spec.rb index 93a202995..51c1f483a 100644 --- a/spec/rspec/mocks/stash_spec.rb +++ b/spec/rspec/mocks/stash_spec.rb @@ -3,7 +3,7 @@ module Mocks RSpec.describe "only stashing the original method" do let(:klass) do Class.new do - def self.foo(arg) + def self.foo(_) :original_value end end diff --git a/spec/rspec/mocks/stub_implementation_spec.rb b/spec/rspec/mocks/stub_implementation_spec.rb index 9507f3830..2c3cb9327 100644 --- a/spec/rspec/mocks/stub_implementation_spec.rb +++ b/spec/rspec/mocks/stub_implementation_spec.rb @@ -3,7 +3,7 @@ module Mocks RSpec.describe "stub implementation" do describe "with no args" do it "execs the block when called" do - obj = double() + obj = double allow(obj).to receive(:foo) { :bar } expect(obj.foo).to eq :bar end @@ -11,16 +11,16 @@ module Mocks describe "with one arg" do it "execs the block with that arg when called" do - obj = double() - allow(obj).to receive(:foo) {|given| given} + obj = double + allow(obj).to receive(:foo) { |given| given } expect(obj.foo(:bar)).to eq :bar end end describe "with variable args" do it "execs the block when called" do - obj = double() - allow(obj).to receive(:foo) {|*given| given.first} + obj = double + allow(obj).to receive(:foo) { |*given| given.first } expect(obj.foo(:bar)).to eq :bar end end diff --git a/spec/rspec/mocks/stub_spec.rb b/spec/rspec/mocks/stub_spec.rb index ebde9681d..37a59d9e0 100644 --- a/spec/rspec/mocks/stub_spec.rb +++ b/spec/rspec/mocks/stub_spec.rb @@ -8,7 +8,8 @@ def existing_class_method existing_private_class_method end - private + private + def existing_private_class_method :original_value end @@ -18,7 +19,6 @@ def existing_instance_method existing_private_instance_method end - private def existing_private_instance_method :original_value end @@ -81,7 +81,7 @@ def existing_private_instance_method it "is cleared when stubbed object when `dup`ed" do allow(@stub).to receive(:foobar).and_return(1) - expect{ @stub.dup.foobar }.to raise_error NoMethodError, /foobar/ + expect { @stub.dup.foobar }.to raise_error NoMethodError, /foobar/ end context "using `with`" do @@ -205,7 +205,7 @@ def object.value; :original; end object.singleton_class.class_eval do def value; :original; end prepend ToBePrepended - prepend Module.new { } + prepend Module.new {} end expect(object.value).to eq :original_prepended @@ -322,21 +322,21 @@ class << self; public :hello; end; it "correctly handles stubbing inherited mixed in class methods" do mod = Module.new do - def method_a - raise "should not execute method_a" - end + def method_a + raise "should not execute method_a" + end - def self.included(other) - other.extend self - end - end + def self.included(other) + other.extend self + end + end a = Class.new { include mod } b = Class.new(a) do - def self.method_b - "executed method_b" - end - end + def self.method_b + "executed method_b" + end + end allow(a).to receive(:method_a) allow(b).to receive(:method_b).and_return("stubbed method_b") @@ -414,14 +414,14 @@ def object.existing_method; :original_value; end end it "returns values in order to consecutive calls" do - allow(@instance).to receive(:msg).and_return("1",2,:three) + allow(@instance).to receive(:msg).and_return("1", 2, :three) expect(@instance.msg).to eq("1") expect(@instance.msg).to eq(2) expect(@instance.msg).to eq(:three) end it "keeps returning last value in consecutive calls" do - allow(@instance).to receive(:msg).and_return("1",2,:three) + allow(@instance).to receive(:msg).and_return("1", 2, :three) expect(@instance.msg).to eq("1") expect(@instance.msg).to eq(2) expect(@instance.msg).to eq(:three) @@ -432,7 +432,7 @@ def object.existing_method; :original_value; end it "yields a specified object" do allow(@instance).to receive(:method_that_yields).and_yield(:yielded_obj) current_value = :value_before - @instance.method_that_yields {|val| current_value = val} + @instance.method_that_yields { |val| current_value = val } expect(current_value).to eq :yielded_obj verify @instance end @@ -441,7 +441,7 @@ def object.existing_method; :original_value; end allow(@instance).to receive(:method_that_yields_multiple_times).and_yield(:yielded_value). and_yield(:another_value) current_value = [] - @instance.method_that_yields_multiple_times {|val| current_value << val} + @instance.method_that_yields_multiple_times { |val| current_value << val } expect(current_value).to eq [:yielded_value, :another_value] verify @instance end @@ -501,7 +501,7 @@ def object.existing_method; :original_value; end }.to raise_error(/received :foo with unexpected arguments/) end - it "complains if called with other arg", :github_issue => [123,147] do + it "complains if called with other arg", :github_issue => [123, 147] do expect { @stub.foo("other") }.to raise_error(/received :foo with unexpected arguments.*Please stub a default value/m) @@ -535,6 +535,5 @@ def object.existing_method; :original_value; end expect(@stub.bar).to eq(15) end end - end end diff --git a/spec/rspec/mocks/stubbed_message_expectations_spec.rb b/spec/rspec/mocks/stubbed_message_expectations_spec.rb index dac373a4e..2181133ee 100644 --- a/spec/rspec/mocks/stubbed_message_expectations_spec.rb +++ b/spec/rspec/mocks/stubbed_message_expectations_spec.rb @@ -16,10 +16,10 @@ }.to raise_error( RSpec::Mocks::MockExpectationError, a_string_including( - %Q|# received :foo with unexpected arguments|, + %Q(# received :foo with unexpected arguments), "expected: (\"first\")", - "got:","(\"second\")", - "(\"third\")")) + "got:", "(\"second\")", + "(\"third\")")) reset dbl end diff --git a/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb b/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb index b91515f9a..057d6e541 100644 --- a/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +++ b/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb @@ -1,6 +1,5 @@ module RSpec module Mocks - RSpec.describe ".allow_message" do let(:subject) { Object.new } @@ -92,8 +91,6 @@ module Mocks verify subject end - end - end end diff --git a/spec/rspec/mocks/test_double_spec.rb b/spec/rspec/mocks/test_double_spec.rb index a260d35dc..945066091 100644 --- a/spec/rspec/mocks/test_double_spec.rb +++ b/spec/rspec/mocks/test_double_spec.rb @@ -10,7 +10,7 @@ module Mocks end it "gives the correct call site for the warning" do - expect_warning_with_call_site(__FILE__, __LINE__+1) + expect_warning_with_call_site(__FILE__, __LINE__ + 1) subject.freeze end diff --git a/spec/rspec/mocks/to_ary_spec.rb b/spec/rspec/mocks/to_ary_spec.rb index 3a9833ae8..4b060afb7 100644 --- a/spec/rspec/mocks/to_ary_spec.rb +++ b/spec/rspec/mocks/to_ary_spec.rb @@ -41,7 +41,7 @@ expect(obj).not_to respond_to(:to_ary) end - it "doesn't respond to to_a", :if => ( RUBY_VERSION.to_f > 1.8 ) do + it "doesn't respond to to_a", :if => (RUBY_VERSION.to_f > 1.8) do expect(obj).not_to respond_to(:to_a) end diff --git a/spec/rspec/mocks/verifying_doubles/class_double_with_class_loaded_spec.rb b/spec/rspec/mocks/verifying_doubles/class_double_with_class_loaded_spec.rb index e03d85c55..f12dac635 100644 --- a/spec/rspec/mocks/verifying_doubles/class_double_with_class_loaded_spec.rb +++ b/spec/rspec/mocks/verifying_doubles/class_double_with_class_loaded_spec.rb @@ -141,7 +141,7 @@ module Mocks context "on a class that has redefined `new`" do it "uses the method signature of the redefined `new` for arg verification" do klass = Class.new(LoadedClass) do - def self.new(a); end + def self.new(_); end end o = class_double(klass) diff --git a/spec/rspec/mocks/verifying_doubles/instance_double_with_class_loaded_spec.rb b/spec/rspec/mocks/verifying_doubles/instance_double_with_class_loaded_spec.rb index 8ff35853e..5455fcaa9 100644 --- a/spec/rspec/mocks/verifying_doubles/instance_double_with_class_loaded_spec.rb +++ b/spec/rspec/mocks/verifying_doubles/instance_double_with_class_loaded_spec.rb @@ -80,8 +80,7 @@ module Mocks o = instance_double('LoadedClass', :defined_instance_method => 25) expect { o.defined_instance_method(:a) - }.to raise_error(ArgumentError, - "Wrong number of arguments. Expected 0, got 1.") + }.to raise_error(ArgumentError, "Wrong number of arguments. Expected 0, got 1.") end if required_kw_args_supported? @@ -131,7 +130,7 @@ module Mocks end end - it 'checks that stubbed methods with required keyword args are ' + + it 'checks that stubbed methods with required keyword args are ' \ 'invoked with the required arguments' do o = instance_double('LoadedClass', :kw_args_method => true) expect { diff --git a/spec/rspec/mocks/verifying_doubles/naming_spec.rb b/spec/rspec/mocks/verifying_doubles/naming_spec.rb index 0acd82fbc..0a15b28fe 100644 --- a/spec/rspec/mocks/verifying_doubles/naming_spec.rb +++ b/spec/rspec/mocks/verifying_doubles/naming_spec.rb @@ -5,7 +5,7 @@ module Mocks RSpec::Matchers.define :fail_expectations_as do |expected| description { "include a meaningful name in the exception" } - def error_message_for(verifying_double) + def error_message_for(_) expect(actual).to have_received(:defined_instance_and_class_method) rescue MockExpectationError, Expectations::ExpectationNotMetError => e e.message @@ -14,8 +14,8 @@ def error_message_for(verifying_double) end failure_message do |actual| - "expected #{actual.inspect} to fail expectations as:\n" + - " #{expected.inspect}, but failed with:\n" + + "expected #{actual.inspect} to fail expectations as:\n" \ + " #{expected.inspect}, but failed with:\n" \ " #{@error_message.inspect}" end diff --git a/spec/rspec/mocks_spec.rb b/spec/rspec/mocks_spec.rb index 94d78438f..ab8243e0f 100644 --- a/spec/rspec/mocks_spec.rb +++ b/spec/rspec/mocks_spec.rb @@ -15,7 +15,8 @@ # to prevent the loading of securerandom by faking out `BasicObject#__id__ lib_preamble.unshift "class BasicObject; def __id__; end; end" if RUBY_VERSION == '1.9.2' - it_behaves_like 'library wide checks', 'rspec-mocks', :preamble_for_lib => lib_preamble, + it_behaves_like 'library wide checks', 'rspec-mocks', + :preamble_for_lib => lib_preamble, :allowed_loaded_feature_regexps => [ /rbconfig/ # loaded by rspec-support ] do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0c563fb2d..8d791dcf6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -54,7 +54,7 @@ def expect_fast_failure_from(double, *fail_with_args, &blk) end module VerificationHelpers - def prevents(msg = //, &block) + def prevents(msg=//, &block) expect(&block).to fail_with msg end end @@ -67,7 +67,7 @@ def self.fake_matcher_description extend RSpec::Matchers::DSL matcher :fake_matcher do |expected| - match {|actual| actual == expected} + match { |actual| actual == expected } description do MatcherHelpers.fake_matcher_description @@ -75,7 +75,6 @@ def self.fake_matcher_description end end - require 'rspec/support/spec' RSpec.configure do |config| @@ -134,7 +133,6 @@ def self.fake_matcher_description end end - RSpec.shared_context "with isolated configuration" do orig_configuration = nil before do diff --git a/spec/support/doubled_classes.rb b/spec/support/doubled_classes.rb index 3150c9f29..eb2132c0e 100644 --- a/spec/support/doubled_classes.rb +++ b/spec/support/doubled_classes.rb @@ -5,12 +5,11 @@ class LoadedClass N = :n INSTANCE = LoadedClass.new - def initialize(a, b) + def initialize(_a, _b) end class << self - - def respond_to?(method_name, include_all = false) + def respond_to?(method_name, include_all=false) return true if method_name == :dynamic_class_method super end @@ -34,16 +33,15 @@ def defined_protected_class_method def defined_private_class_method end - end def defined_instance_method end - def instance_method_with_two_args(a, b) + def instance_method_with_two_args(_a, _b) end - def instance_method_with_only_defaults(a=1, b=2) + def instance_method_with_only_defaults(_a=1, _b=2) end def defined_instance_and_class_method @@ -63,7 +61,7 @@ def mixed_args_method(foo, bar, optional_arg_1:1, optional_arg_2:2) def send(*) end - def respond_to?(method_name, include_all = false) + def respond_to?(method_name, include_all=false) return true if method_name == :dynamic_instance_method super end