File: null_object_spec.rb

package info (click to toggle)
ruby-factory-bot 6.5.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,492 kB
  • sloc: ruby: 9,242; makefile: 6; sh: 4
file content (22 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
describe FactoryBot::NullObject do
  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(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 { null_object.__send__(method_name) }.to raise_error(NoMethodError)
      expect(null_object).not_to respond_to(method_name)
    end
  end
end