From 95188e2e78d7f6000f7b465f00a41f47ef3ad017 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Thu, 1 Jun 2017 09:54:02 -0700 Subject: [PATCH] Switches mocking library to rspec --- Gemfile.lock | 7 ----- factory_girl.gemspec | 2 -- .../attributes_from_instance_spec.rb | 4 +-- .../attribute/association_spec.rb | 24 +++++++++++++-- spec/factory_girl/attribute/dynamic_spec.rb | 18 +++++++++++- .../factory_girl/declaration/implicit_spec.rb | 4 +-- spec/factory_girl/declaration_list_spec.rb | 29 ++++++++++++------- spec/factory_girl/definition_proxy_spec.rb | 2 +- spec/factory_girl/definition_spec.rb | 12 ++++---- .../disallows_duplicates_registry_spec.rb | 8 +++-- .../evaluator_class_definer_spec.rb | 8 +++-- spec/factory_girl/factory_spec.rb | 19 +++++++----- spec/factory_girl/find_definitions_spec.rb | 11 +++---- spec/factory_girl/registry_spec.rb | 4 +-- spec/factory_girl/sequence_spec.rb | 2 +- .../strategy/attributes_for_spec.rb | 2 +- spec/factory_girl/strategy/create_spec.rb | 19 +++++++++++- spec/factory_girl/strategy/stub_spec.rb | 4 ++- spec/factory_girl/strategy_calculator_spec.rb | 5 +++- spec/spec_helper.rb | 9 ++++-- spec/support/matchers/delegate.rb | 6 ++-- spec/support/shared_examples/strategy.rb | 28 +++++++++--------- 22 files changed, 151 insertions(+), 76 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2f1aa0b..dc17004 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,8 +35,6 @@ GEM ffi (~> 1.9.10) rspec-expectations (>= 2.99) thor (~> 0.19) - bourne (1.6.0) - mocha (~> 1.1) builder (3.2.2) childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) @@ -61,10 +59,7 @@ GEM jdbc-sqlite3 (3.8.11.2) json (1.8.6) json (1.8.6-java) - metaclass (0.0.4) minitest (5.9.1) - mocha (1.1.0) - metaclass (~> 0.0.1) multi_json (1.11.2) multi_test (0.1.2) rake (10.5.0) @@ -107,11 +102,9 @@ DEPENDENCIES activerecord-jdbcsqlite3-adapter appraisal (~> 2.1.0) aruba - bourne cucumber (~> 1.3.15) factory_girl! jdbc-sqlite3 - mocha (>= 0.12.8) rspec (~> 3.0) rspec-its (~> 1.0) simplecov diff --git a/factory_girl.gemspec b/factory_girl.gemspec index 5f0d004..24f1cc4 100644 --- a/factory_girl.gemspec +++ b/factory_girl.gemspec @@ -28,8 +28,6 @@ Gem::Specification.new do |s| s.add_development_dependency("timecop") s.add_development_dependency("simplecov") s.add_development_dependency("aruba") - s.add_development_dependency("mocha", ">= 0.12.8") - s.add_development_dependency("bourne") s.add_development_dependency("appraisal", "~> 2.1.0") s.add_development_dependency("activerecord", ">= 3.0.0") s.add_development_dependency("yard") diff --git a/spec/acceptance/attributes_from_instance_spec.rb b/spec/acceptance/attributes_from_instance_spec.rb index 0d6b6d2..7d644ec 100644 --- a/spec/acceptance/attributes_from_instance_spec.rb +++ b/spec/acceptance/attributes_from_instance_spec.rb @@ -25,9 +25,9 @@ describe "calling methods on the model instance" do end it "doesn't instantiate a record with attributes_for" do - User.stubs(:new) + allow(User).to receive(:new) FactoryGirl.attributes_for(:user) - expect(User).to have_received(:new).never + expect(User).to_not have_received(:new) end end diff --git a/spec/factory_girl/attribute/association_spec.rb b/spec/factory_girl/attribute/association_spec.rb index 02bc993..140c8fe 100644 --- a/spec/factory_girl/attribute/association_spec.rb +++ b/spec/factory_girl/attribute/association_spec.rb @@ -4,10 +4,30 @@ describe FactoryGirl::Attribute::Association do let(:name) { :author } let(:factory) { :user } let(:overrides) { { first_name: "John" } } - let(:association) { stub("association") } + let(:association) { double("association") } subject { FactoryGirl::Attribute::Association.new(name, factory, overrides) } - before { subject.stubs(association: association) } + before do + RSpec.configure do |config| + config.mock_with :rspec do |mocks| + # FactoryGirl::Attribute::Association does not explicitly define an + # `association` instance method, so when we stub it out below, + # rspec-mock complains that it can't find the method. + # + # Therefore, temporarily turn off this feature. + mocks.verify_partial_doubles = false + end + end + allow(subject).to receive(:association).and_return association + end + + after do + RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + end + end it { should be_association } its(:name) { should eq name } diff --git a/spec/factory_girl/attribute/dynamic_spec.rb b/spec/factory_girl/attribute/dynamic_spec.rb index fc6fe5e..d299566 100644 --- a/spec/factory_girl/attribute/dynamic_spec.rb +++ b/spec/factory_girl/attribute/dynamic_spec.rb @@ -29,7 +29,23 @@ describe FactoryGirl::Attribute::Dynamic do let(:result) { "other attribute value" } before do - subject.stubs(attribute_defined_on_attribute: result) + RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = false + end + end + + allow( + subject, + ).to receive(:attribute_defined_on_attribute).and_return result + end + + after do + RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + end end it "evaluates the attribute from the attribute" do diff --git a/spec/factory_girl/declaration/implicit_spec.rb b/spec/factory_girl/declaration/implicit_spec.rb index 4d5186e..80e340b 100644 --- a/spec/factory_girl/declaration/implicit_spec.rb +++ b/spec/factory_girl/declaration/implicit_spec.rb @@ -7,7 +7,7 @@ describe FactoryGirl::Declaration::Implicit do context "with a known factory" do before do - FactoryGirl.factories.stubs(:registered? => true) + allow(FactoryGirl.factories).to receive(:registered?).and_return true end it { should be_association } @@ -16,7 +16,7 @@ describe FactoryGirl::Declaration::Implicit do context "with a known sequence" do before do - FactoryGirl.sequences.stubs(:registered? => true) + allow(FactoryGirl.sequences).to receive(:registered?).and_return true end it { should_not be_association } diff --git a/spec/factory_girl/declaration_list_spec.rb b/spec/factory_girl/declaration_list_spec.rb index f171159..a36784e 100644 --- a/spec/factory_girl/declaration_list_spec.rb +++ b/spec/factory_girl/declaration_list_spec.rb @@ -1,20 +1,27 @@ require "spec_helper" describe FactoryGirl::DeclarationList, "#attributes" do - let(:static_attribute_1) { stub("static attribute 1") } - let(:static_attribute_2) { stub("static attribute 2") } - let(:dynamic_attribute_1) { stub("dynamic attribute 1") } - let(:static_declaration) { stub("static declaration", to_attributes: [static_attribute_1, static_attribute_2]) } - let(:dynamic_declaration) { stub("static declaration", to_attributes: [dynamic_attribute_1]) } + let(:static_attribute_1) { double("static attribute 1") } + let(:static_attribute_2) { double("static attribute 2") } + let(:dynamic_attribute_1) { double("dynamic attribute 1") } + let(:static_declaration) do + double( + "static declaration", + to_attributes: [static_attribute_1, static_attribute_2], + ) + end + let(:dynamic_declaration) do + double("static declaration", to_attributes: [dynamic_attribute_1]) + end it "returns an AttributeList" do expect(subject.attributes).to be_a(FactoryGirl::AttributeList) end - let(:attribute_list) { stub("attribute list", define_attribute: true) } + let(:attribute_list) { double("attribute list", define_attribute: true) } it "defines each attribute on the attribute list" do - FactoryGirl::AttributeList.stubs(new: attribute_list) + allow(FactoryGirl::AttributeList).to receive(:new).and_return attribute_list subject.declare_attribute(static_declaration) subject.declare_attribute(dynamic_declaration) @@ -28,9 +35,11 @@ describe FactoryGirl::DeclarationList, "#attributes" do end describe FactoryGirl::DeclarationList, "#declare_attribute" do - let(:declaration_1) { stub("declaration", name: "declaration 1") } - let(:declaration_2) { stub("declaration", name: "declaration 2") } - let(:declaration_with_same_name) { stub("declaration", name: "declaration 1") } + let(:declaration_1) { double("declaration", name: "declaration 1") } + let(:declaration_2) { double("declaration", name: "declaration 2") } + let(:declaration_with_same_name) do + double("declaration", name: "declaration 1") + end context "when not overridable" do it "adds the declaration to the list" do diff --git a/spec/factory_girl/definition_proxy_spec.rb b/spec/factory_girl/definition_proxy_spec.rb index 98754ca..e7f4a25 100644 --- a/spec/factory_girl/definition_proxy_spec.rb +++ b/spec/factory_girl/definition_proxy_spec.rb @@ -87,7 +87,7 @@ describe FactoryGirl::DefinitionProxy, "#sequence" do subject { FactoryGirl::Definition.new } let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) } - before { FactoryGirl::Sequence.stubs(:new) } + before { allow(FactoryGirl::Sequence).to receive(:new) } it "creates a new sequence starting at 1" do proxy.sequence(:great) diff --git a/spec/factory_girl/definition_spec.rb b/spec/factory_girl/definition_spec.rb index a97b7f8..7ed2d60 100644 --- a/spec/factory_girl/definition_spec.rb +++ b/spec/factory_girl/definition_spec.rb @@ -9,15 +9,17 @@ describe FactoryGirl::Definition, "with a name" do subject { FactoryGirl::Definition.new(name) } it "creates a new attribute list with the name passed" do - FactoryGirl::DeclarationList.stubs(:new) + allow(FactoryGirl::DeclarationList).to receive(:new) subject expect(FactoryGirl::DeclarationList).to have_received(:new).with(name) end end describe FactoryGirl::Definition, "#overridable" do - let(:list) { stub("declaration list", overridable: true) } - before { FactoryGirl::DeclarationList.stubs(new: list) } + let(:list) { double("declaration list", overridable: true) } + before do + allow(FactoryGirl::DeclarationList).to receive(:new).and_return list + end it "sets the declaration list as overridable" do expect(subject.overridable).to eq subject @@ -26,8 +28,8 @@ describe FactoryGirl::Definition, "#overridable" do end describe FactoryGirl::Definition, "defining traits" do - let(:trait_1) { stub("trait") } - let(:trait_2) { stub("trait") } + let(:trait_1) { double("trait") } + let(:trait_2) { double("trait") } it "maintains a list of traits" do subject.define_trait(trait_1) diff --git a/spec/factory_girl/disallows_duplicates_registry_spec.rb b/spec/factory_girl/disallows_duplicates_registry_spec.rb index b3fb9a6..39b352a 100644 --- a/spec/factory_girl/disallows_duplicates_registry_spec.rb +++ b/spec/factory_girl/disallows_duplicates_registry_spec.rb @@ -1,18 +1,20 @@ require "spec_helper" describe FactoryGirl::Decorator::DisallowsDuplicatesRegistry do - let(:registry) { stub("registry", name: 'Great thing', register: true) } + let(:registry) do + double("registry", name: "Great thing", register: true) + end subject { described_class.new(registry) } it "delegates #register to the registry when not registered" do - registry.stubs(registered?: false) + allow(registry).to receive(:registered?).and_return false subject.register(:awesome, {}) expect(registry).to have_received(:register).with(:awesome, {}) end it "raises when attempting to #register a previously registered strategy" do - registry.stubs(registered?: true) + allow(registry).to receive(:registered?).and_return true expect { subject.register(:same_name, {}) }. to raise_error(FactoryGirl::DuplicateDefinitionError, "Great thing already registered: same_name") end diff --git a/spec/factory_girl/evaluator_class_definer_spec.rb b/spec/factory_girl/evaluator_class_definer_spec.rb index e70cc1e..aa66142 100644 --- a/spec/factory_girl/evaluator_class_definer_spec.rb +++ b/spec/factory_girl/evaluator_class_definer_spec.rb @@ -15,7 +15,11 @@ describe FactoryGirl::EvaluatorClassDefiner do end it "evaluates the block in the context of the evaluator" do - dependency_attribute = stub("dependency", name: :dependency, to_proc: -> { 1 }) + dependency_attribute = double( + "dependency", + name: :dependency, + to_proc: -> { 1 }, + ) dependency_attribute = stub_attribute(:dependency) { 1 } attribute = stub_attribute(:attribute) { dependency + 1 } evaluator = define_evaluator(attributes: [dependency_attribute, attribute]) @@ -72,6 +76,6 @@ describe FactoryGirl::EvaluatorClassDefiner do def stub_attribute(name = :attribute, &value) value ||= -> {} - stub(name.to_s, name: name.to_sym, to_proc: value) + double(name.to_s, name: name.to_sym, to_proc: value) end end diff --git a/spec/factory_girl/factory_spec.rb b/spec/factory_girl/factory_spec.rb index 2e0cc3e..ef78e99 100644 --- a/spec/factory_girl/factory_spec.rb +++ b/spec/factory_girl/factory_spec.rb @@ -17,8 +17,8 @@ describe FactoryGirl::Factory do end it "passes a custom creation block" do - strategy = stub("strategy", result: nil, add_observer: true) - FactoryGirl::Strategy::Build.stubs(new: strategy) + strategy = double("strategy", result: nil, add_observer: true) + allow(FactoryGirl::Strategy::Build).to receive(:new).and_return strategy block = -> {} factory = FactoryGirl::Factory.new(:object) factory.to_create(&block) @@ -229,15 +229,20 @@ describe FactoryGirl::Factory, "running a factory" do subject { FactoryGirl::Factory.new(:user) } let(:attribute) { FactoryGirl::Attribute::Static.new(:name, "value", false) } let(:declaration) { FactoryGirl::Declaration::Static.new(:name, "value", false) } - let(:strategy) { stub("strategy", result: "result", add_observer: true) } + let(:strategy) do + double("strategy", result: "result", add_observer: true) + end let(:attributes) { [attribute] } - let(:attribute_list) { stub('attribute-list', declarations: [declaration], to_a: attributes) } + let(:attribute_list) do + double("attribute-list", declarations: [declaration], to_a: attributes) + end before do define_model("User", name: :string) - FactoryGirl::Declaration::Static.stubs(new: declaration) - declaration.stubs(to_attributes: attributes) - FactoryGirl::Strategy::Build.stubs(new: strategy) + allow(FactoryGirl::Declaration::Static).to receive(:new). + and_return declaration + allow(declaration).to receive(:to_attributes).and_return attributes + allow(FactoryGirl::Strategy::Build).to receive(:new).and_return strategy subject.declare_attribute(declaration) end diff --git a/spec/factory_girl/find_definitions_spec.rb b/spec/factory_girl/find_definitions_spec.rb index 758f6b8..b029375 100644 --- a/spec/factory_girl/find_definitions_spec.rb +++ b/spec/factory_girl/find_definitions_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' shared_examples_for "finds definitions" do before do - FactoryGirl.stubs(:load) + allow(FactoryGirl).to receive(:load) FactoryGirl.find_definitions end @@ -79,10 +79,11 @@ describe "definition loading" do in_directory_with_files File.join(dir, 'factories', 'b.rb'), File.join(dir, 'factories', 'a.rb') it "loads the files in the right order" do - FactoryGirl.stubs(:load) - sorted_load_order = sequence("load order") - FactoryGirl.expects(:load).with(includes("a.rb")).in_sequence(sorted_load_order) - FactoryGirl.expects(:load).with(includes("b.rb")).in_sequence(sorted_load_order) + wd = File.dirname(__FILE__) + file_b = File.join(wd, "tmp", dir, "factories", "b.rb") + file_a = File.join(wd, "tmp", dir, "factories", "a.rb") + allow(FactoryGirl).to receive(:load).with(file_a).ordered + allow(FactoryGirl).to receive(:load).with(file_b).ordered FactoryGirl.find_definitions end end diff --git a/spec/factory_girl/registry_spec.rb b/spec/factory_girl/registry_spec.rb index ef3ebf7..e3b3541 100644 --- a/spec/factory_girl/registry_spec.rb +++ b/spec/factory_girl/registry_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe FactoryGirl::Registry do - let(:registered_object) { stub("registered object") } - let(:second_registered_object) { stub("second registered object") } + let(:registered_object) { double("registered object") } + let(:second_registered_object) { double("second registered object") } subject { FactoryGirl::Registry.new("Great thing") } diff --git a/spec/factory_girl/sequence_spec.rb b/spec/factory_girl/sequence_spec.rb index 730628c..82a90c6 100644 --- a/spec/factory_girl/sequence_spec.rb +++ b/spec/factory_girl/sequence_spec.rb @@ -78,7 +78,7 @@ describe FactoryGirl::Sequence do describe "a custom sequence and scope" do subject { FactoryGirl::Sequence.new(:name, 'A') { |n| "=#{n}#{foo}" } } - let(:scope) { stub('scope', foo: 'attribute') } + let(:scope) { double("scope", foo: "attribute") } it 'increments within the correct scope' do expect(subject.next(scope)).to eq '=Aattribute' diff --git a/spec/factory_girl/strategy/attributes_for_spec.rb b/spec/factory_girl/strategy/attributes_for_spec.rb index 2d320c1..3a2f012 100644 --- a/spec/factory_girl/strategy/attributes_for_spec.rb +++ b/spec/factory_girl/strategy/attributes_for_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe FactoryGirl::Strategy::AttributesFor do let(:result) { { name: "John Doe", gender: "Male", admin: false } } - let(:evaluation) { stub("evaluation", hash: result) } + let(:evaluation) { double("evaluation", hash: result) } it_should_behave_like "strategy without association support" diff --git a/spec/factory_girl/strategy/create_spec.rb b/spec/factory_girl/strategy/create_spec.rb index a192672..8f0cc8a 100644 --- a/spec/factory_girl/strategy/create_spec.rb +++ b/spec/factory_girl/strategy/create_spec.rb @@ -1,6 +1,22 @@ require 'spec_helper' describe FactoryGirl::Strategy::Create do + before do + RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = false + end + end + end + + after do + RSpec.configure do |config| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + end + end + it_should_behave_like "strategy with association support", :create it_should_behave_like "strategy with callbacks", :after_build, :before_create, :after_create @@ -18,7 +34,8 @@ describe FactoryGirl::Strategy::Create do end evaluation = evaluation_class.new - evaluation.stubs(object: nil, notify: nil) + allow(evaluation).to receive(:object) + allow(evaluation).to receive(:notify) subject.result(evaluation) expect(evaluation.block_run).to be true end diff --git a/spec/factory_girl/strategy/stub_spec.rb b/spec/factory_girl/strategy/stub_spec.rb index bdbe7b0..8d9c44d 100644 --- a/spec/factory_girl/strategy/stub_spec.rb +++ b/spec/factory_girl/strategy/stub_spec.rb @@ -32,7 +32,9 @@ describe FactoryGirl::Strategy::Stub do end.new end - let(:evaluation) { stub("evaluation", object: result_instance, notify: true) } + let(:evaluation) do + double("evaluation", object: result_instance, notify: true) + end it { expect(subject.result(evaluation)).not_to be_new_record } it { expect(subject.result(evaluation)).to be_persisted } diff --git a/spec/factory_girl/strategy_calculator_spec.rb b/spec/factory_girl/strategy_calculator_spec.rb index 58fe5dc..f1ce62d 100644 --- a/spec/factory_girl/strategy_calculator_spec.rb +++ b/spec/factory_girl/strategy_calculator_spec.rb @@ -14,7 +14,10 @@ describe FactoryGirl::StrategyCalculator do end context "when a symbol" do - before { FactoryGirl.stubs(:strategy_by_name).returns(strategy) } + before do + allow(FactoryGirl).to receive(:strategy_by_name).and_return(strategy) + end + subject { FactoryGirl::StrategyCalculator.new(:build).strategy } it "finds the strategy by name" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d71f0a8..ded5479 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,14 +8,17 @@ require 'rspec/its' require "simplecov" require 'factory_girl' -require "mocha/api" -require "bourne" require "timecop" Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) } RSpec.configure do |config| - config.mock_framework = :mocha + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on a + # real object. This is generally recommended, and will default to `true` in + # RSpec 4. + mocks.verify_partial_doubles = true + end config.include DeclarationMatchers diff --git a/spec/support/matchers/delegate.rb b/spec/support/matchers/delegate.rb index 6023a61..981ea52 100644 --- a/spec/support/matchers/delegate.rb +++ b/spec/support/matchers/delegate.rb @@ -12,14 +12,12 @@ RSpec::Matchers.define :delegate do |delegated_method| end match do |instance| - extend Mocha::API - @instance = instance @args ||= [] return_value = 'stubbed return value' method_on_target = @method_on_target || delegated_method - stubbed_target = stub('stubbed_target', method_on_target => return_value) - @instance.stubs(@target_method => stubbed_target) + stubbed_target = double("stubbed_target", method_on_target => return_value) + allow(@instance).to receive(@target_method).and_return stubbed_target begin @instance.send(delegated_method, *@args) == return_value rescue NoMethodError diff --git a/spec/support/shared_examples/strategy.rb b/spec/support/shared_examples/strategy.rb index f879ef4..3260938 100644 --- a/spec/support/shared_examples/strategy.rb +++ b/spec/support/shared_examples/strategy.rb @@ -1,5 +1,5 @@ shared_examples_for "strategy without association support" do - let(:factory) { stub("associate_factory") } + let(:factory) { double("associate_factory") } let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) } def association_named(name, overrides) @@ -8,9 +8,9 @@ shared_examples_for "strategy without association support" do end before do - FactoryGirl.stubs(factory_by_name: factory) - factory.stubs(:compile) - factory.stubs(:run) + allow(FactoryGirl).to receive(:factory_by_name).and_return factory + allow(factory).to receive(:compile) + allow(factory).to receive(:run) end it "returns nil when accessing an association" do @@ -19,7 +19,7 @@ shared_examples_for "strategy without association support" do end shared_examples_for "strategy with association support" do |factory_girl_strategy_name| - let(:factory) { stub("associate_factory") } + let(:factory) { double("associate_factory") } def association_named(name, strategy, overrides) runner = FactoryGirl::FactoryRunner.new(name, strategy, [overrides]) @@ -27,9 +27,9 @@ shared_examples_for "strategy with association support" do |factory_girl_strateg end before do - FactoryGirl.stubs(factory_by_name: factory) - factory.stubs(:compile) - factory.stubs(:run) + allow(FactoryGirl).to receive(:factory_by_name).and_return factory + allow(factory).to receive(:compile) + allow(factory).to receive(:run) end it "runs the factory with the correct overrides" do @@ -44,7 +44,7 @@ shared_examples_for "strategy with association support" do |factory_girl_strateg end shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_name| - let(:factory) { stub("associate_factory") } + let(:factory) { double("associate_factory") } def association_named(name, overrides) runner = FactoryGirl::FactoryRunner.new(name, overrides[:strategy], [overrides.except(:strategy)]) @@ -52,9 +52,9 @@ shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_n end before do - FactoryGirl.stubs(factory_by_name: factory) - factory.stubs(:compile) - factory.stubs(:run) + allow(FactoryGirl).to receive(:factory_by_name).and_return factory + allow(factory).to receive(:compile) + allow(factory).to receive(:run) end it "runs the factory with the correct overrides" do @@ -75,7 +75,9 @@ shared_examples_for "strategy with callbacks" do |*callback_names| end.new end - let(:evaluation) { stub("evaluation", object: result_instance, notify: true, create: nil) } + let(:evaluation) do + double("evaluation", object: result_instance, notify: true, create: nil) + end it "runs the callbacks #{callback_names} with the evaluation's object" do subject.result(evaluation)