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

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

Instance Method Summary collapse

Methods inherited from Record

#==, #hash, #to_s

Constructor Details

#initialize(method_stub, conversion_type) ⇒ AllowRecord

Returns a new instance of AllowRecord.



189
190
191
192
# File 'lib/transpec/syntax/method_stub.rb', line 189

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

Instance Method Details

#converted_syntaxObject



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

def 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

#original_syntaxObject



194
195
196
197
198
199
200
201
202
203
# File 'lib/transpec/syntax/method_stub.rb', line 194

def 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