2017-10-20 15:20:28 -04:00
|
|
|
describe FactoryBot::NullObject do
|
2012-04-19 21:34:47 -04:00
|
|
|
it "responds to the given methods" do
|
2019-10-23 18:22:53 -04:00
|
|
|
methods_to_respond_to = %w[id age name admin?]
|
|
|
|
null_object = FactoryBot::NullObject.new(methods_to_respond_to)
|
|
|
|
|
2012-04-19 21:34:47 -04:00
|
|
|
methods_to_respond_to.each do |method_name|
|
2019-10-23 18:22:53 -04:00
|
|
|
expect(null_object.__send__(method_name)).to be_nil
|
|
|
|
expect(null_object).to respond_to(method_name)
|
2012-04-19 21:34:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not respond to other methods" do
|
2019-10-23 18:22:53 -04:00
|
|
|
methods_to_respond_to = %w[id age name admin?]
|
|
|
|
methods_to_not_respond_to = %w[email date_of_birth title]
|
|
|
|
null_object = FactoryBot::NullObject.new(methods_to_respond_to)
|
|
|
|
|
2012-04-19 21:34:47 -04:00
|
|
|
methods_to_not_respond_to.each do |method_name|
|
2019-10-23 18:22:53 -04:00
|
|
|
expect { null_object.__send__(method_name) }.to raise_error(NoMethodError)
|
|
|
|
expect(null_object).not_to respond_to(method_name)
|
2012-04-19 21:34:47 -04:00
|
|
|
end
|
|
|
|
end
|
2012-01-08 00:23:25 -05:00
|
|
|
end
|