Class: Transpec::Syntax::MethodStub::AllowRecordBuilder
- Inherits:
-
RecordBuilder
- Object
- RecordBuilder
- Transpec::Syntax::MethodStub::AllowRecordBuilder
- Defined in:
- lib/transpec/syntax/method_stub.rb
Instance Attribute Summary collapse
-
#conversion_type ⇒ Object
readonly
Returns the value of attribute conversion_type.
-
#method_stub ⇒ Object
readonly
Returns the value of attribute method_stub.
Instance Method Summary collapse
-
#initialize(method_stub, conversion_type) ⇒ AllowRecordBuilder
constructor
A new instance of AllowRecordBuilder.
- #new_syntax ⇒ Object
- #old_syntax ⇒ Object
Methods inherited from RecordBuilder
Constructor Details
#initialize(method_stub, conversion_type) ⇒ AllowRecordBuilder
Returns a new instance of AllowRecordBuilder.
175 176 177 178 |
# File 'lib/transpec/syntax/method_stub.rb', line 175 def initialize(method_stub, conversion_type) @method_stub = method_stub @conversion_type = conversion_type end |
Instance Attribute Details
#conversion_type ⇒ Object (readonly)
Returns the value of attribute conversion_type.
173 174 175 |
# File 'lib/transpec/syntax/method_stub.rb', line 173 def conversion_type @conversion_type end |
#method_stub ⇒ Object (readonly)
Returns the value of attribute method_stub.
173 174 175 |
# File 'lib/transpec/syntax/method_stub.rb', line 173 def method_stub @method_stub end |
Instance Method Details
#new_syntax ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/transpec/syntax/method_stub.rb', line 191 def new_syntax syntax = method_stub.any_instance? ? 'allow_any_instance_of(Klass)' : 'allow(obj)' syntax << '.to ' case conversion_type when :allow_to_receive syntax << 'receive(:message)' syntax << '.and_return(value)' if method_stub.hash_arg? syntax << '.and_call_original' if method_stub.unstub? when :allow_to_receive_messages syntax << 'receive_messages(:message => value)' when :allow_to_receive_message_chain syntax << 'receive_message_chain(:message1, :message2)' end syntax end |
#old_syntax ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/transpec/syntax/method_stub.rb', line 180 def old_syntax syntax = method_stub.any_instance? ? 'Klass.any_instance' : 'obj' syntax << ".#{method_stub.method_name}" if method_stub.method_name == :stub_chain syntax << '(:message1, :message2)' else syntax << (method_stub.hash_arg? ? '(:message => value)' : '(:message)') end end |