diff --git a/lib/factory_bot/definition_proxy.rb b/lib/factory_bot/definition_proxy.rb index 18686a7..aaa70ac 100644 --- a/lib/factory_bot/definition_proxy.rb +++ b/lib/factory_bot/definition_proxy.rb @@ -78,7 +78,9 @@ module FactoryBot elsif args.first.respond_to?(:has_key?) && args.first.has_key?(:factory) association(name, *args) else - super(name, *args, &block) + raise NoMethodError.new( + "undefined method '#{name}' in '#{@definition.name}' factory", + ) end end diff --git a/spec/factory_bot/definition_proxy_spec.rb b/spec/factory_bot/definition_proxy_spec.rb index 52e0ca2..ee6170e 100644 --- a/spec/factory_bot/definition_proxy_spec.rb +++ b/spec/factory_bot/definition_proxy_spec.rb @@ -56,9 +56,15 @@ describe FactoryBot::DefinitionProxy, "#method_missing" do expect(subject).to have_dynamic_declaration(:attribute_name).with_value(attribute_value) end - it "calls super" do + it "raises a NoMethodError" do + definition = FactoryBot::Definition.new(:broken) + proxy = FactoryBot::DefinitionProxy.new(definition) + invalid_call = -> { proxy.static_attributes_are_gone true } - expect(invalid_call).to raise_error(NoMethodError) + expect(invalid_call).to raise_error( + NoMethodError, + "undefined method 'static_attributes_are_gone' in 'broken' factory", + ) end end