2017-10-20 15:20:28 -04:00
|
|
|
describe FactoryBot::NullObject do
|
2012-04-19 21:34:47 -04:00
|
|
|
let(:methods_to_respond_to) { %w[id age name admin?] }
|
|
|
|
let(:methods_to_not_respond_to) { %w[email date_of_birth title] }
|
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
subject { FactoryBot::NullObject.new(methods_to_respond_to) }
|
2012-04-19 21:34:47 -04:00
|
|
|
|
|
|
|
it "responds to the given methods" do
|
|
|
|
methods_to_respond_to.each do |method_name|
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject.__send__(method_name)).to be_nil
|
|
|
|
expect(subject).to respond_to(method_name)
|
2012-04-19 21:34:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not respond to other methods" do
|
|
|
|
methods_to_not_respond_to.each do |method_name|
|
|
|
|
expect { subject.__send__(method_name) }.to raise_error(NoMethodError)
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject).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
|