Class: TestBench::Fixtures::ConfigureReceiver
- Inherits:
-
Object
- Object
- TestBench::Fixtures::ConfigureReceiver
- Includes:
- TestBench::Fixture
- Defined in:
- lib/test_bench/fixtures/configure_receiver.rb
Instance Attribute Summary collapse
-
#cls ⇒ Object
readonly
Returns the value of attribute cls.
-
#default_attr_name ⇒ Object
readonly
Returns the value of attribute default_attr_name.
Class Method Summary collapse
Instance Method Summary collapse
- #args ⇒ Object
- #call ⇒ Object
- #configure(receiver, attr_name: nil) ⇒ Object
-
#initialize(cls, default_attr_name, args = nil, kwargs = nil) ⇒ ConfigureReceiver
constructor
A new instance of ConfigureReceiver.
- #kwargs ⇒ Object
Constructor Details
#initialize(cls, default_attr_name, args = nil, kwargs = nil) ⇒ ConfigureReceiver
Returns a new instance of ConfigureReceiver.
17 18 19 20 21 22 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 17 def initialize(cls, default_attr_name, args=nil, kwargs=nil) @cls = cls @default_attr_name = default_attr_name @args = args @kwargs = kwargs end |
Instance Attribute Details
#cls ⇒ Object (readonly)
Returns the value of attribute cls.
6 7 8 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 6 def cls @cls end |
#default_attr_name ⇒ Object (readonly)
Returns the value of attribute default_attr_name.
7 8 9 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 7 def default_attr_name @default_attr_name end |
Class Method Details
.build(cls, *args, attr_name:, **kwargs) ⇒ Object
24 25 26 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 24 def self.build(cls, *args, attr_name:, **kwargs) new(cls, attr_name, args, kwargs) end |
Instance Method Details
#args ⇒ Object
9 10 11 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 9 def args @args ||= [] end |
#call ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 28 def call test "Responds to configure" do assert(cls.respond_to?(:configure)) end or return context do receiver = OpenStruct.new instance = configure(receiver) test "Attribute is set on receiver" do refute(receiver.public_send(default_attr_name).nil?) end test "Returns the instance that was assigned" do assert(receiver.public_send(default_attr_name).equal?(instance)) end end context "Optional Attribute Name" do context "Given" do receiver = OpenStruct.new attr_name = :given_attr_name configure(receiver, attr_name: attr_name) test "Given attribute is set on receiver (Attribute: #{attr_name})" do refute(receiver.public_send(attr_name).nil?) end test "Default attribute is not set on receiver" do assert(receiver.public_send(default_attr_name).nil?) end end context "Omitted" do receiver = OpenStruct.new configure(receiver) test "Default attribute is set on receiver (Attribute: #{default_attr_name})" do refute(receiver.public_send(default_attr_name).nil?) end end end end |
#configure(receiver, attr_name: nil) ⇒ Object
75 76 77 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 75 def configure(receiver, attr_name: nil) cls.configure(receiver, *args, attr_name: attr_name, **kwargs) end |
#kwargs ⇒ Object
13 14 15 |
# File 'lib/test_bench/fixtures/configure_receiver.rb', line 13 def kwargs @kwargs ||= {} end |