Class: Transpec::Syntax::MethodStub::AllowRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/transpec/syntax/method_stub.rb

Constant Summary

Constants inherited from Record

Record::OVERRIDDE_FORBIDDEN_METHODS

Instance Attribute Summary

Attributes inherited from Record

#annotation, #converted_syntax_type, #original_syntax_type

Instance Method Summary collapse

Methods inherited from Record

#==, #converted_syntax, #hash, #original_syntax, #to_s

Constructor Details

#initialize(method_stub, conversion_type) ⇒ AllowRecord

Returns a new instance of AllowRecord.



186
187
188
189
# File 'lib/transpec/syntax/method_stub.rb', line 186

def initialize(method_stub, conversion_type)
  @method_stub = method_stub
  @conversion_type = conversion_type
end

Instance Method Details

#build_converted_syntaxObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/transpec/syntax/method_stub.rb', line 202

def build_converted_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?
  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

#build_original_syntaxObject



191
192
193
194
195
196
197
198
199
200
# File 'lib/transpec/syntax/method_stub.rb', line 191

def build_original_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