From c62ca43d1772ba3e77512d832c187c6b56a05d05 Mon Sep 17 00:00:00 2001 From: Richie Thomas Date: Wed, 23 Oct 2019 15:22:53 -0700 Subject: [PATCH] Refactor null_object_spec.rb to conform to Let's Not style (#1348) --- spec/factory_bot/null_object_spec.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/spec/factory_bot/null_object_spec.rb b/spec/factory_bot/null_object_spec.rb index 134a23c..5ef77a5 100644 --- a/spec/factory_bot/null_object_spec.rb +++ b/spec/factory_bot/null_object_spec.rb @@ -1,20 +1,22 @@ describe FactoryBot::NullObject do - let(:methods_to_respond_to) { %w[id age name admin?] } - let(:methods_to_not_respond_to) { %w[email date_of_birth title] } - - subject { FactoryBot::NullObject.new(methods_to_respond_to) } - it "responds to the given methods" do + methods_to_respond_to = %w[id age name admin?] + null_object = FactoryBot::NullObject.new(methods_to_respond_to) + methods_to_respond_to.each do |method_name| - expect(subject.__send__(method_name)).to be_nil - expect(subject).to respond_to(method_name) + expect(null_object.__send__(method_name)).to be_nil + expect(null_object).to respond_to(method_name) end end it "does not respond to other methods" do + 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) + methods_to_not_respond_to.each do |method_name| - expect { subject.__send__(method_name) }.to raise_error(NoMethodError) - expect(subject).not_to respond_to(method_name) + expect { null_object.__send__(method_name) }.to raise_error(NoMethodError) + expect(null_object).not_to respond_to(method_name) end end end