Class: MinitestToRspec::Rspec::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest_to_rspec/rspec/stub.rb

Overview

Represents a ‘receive` matcher from RSpec. Conceptually the same as `Minitest::Stub`.

Instance Method Summary collapse

Constructor Details

#initialize(receiver, any_instance, message, with, returns, count) ⇒ Stub

Returns a new instance of Stub.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/minitest_to_rspec/rspec/stub.rb', line 10

def initialize(receiver, any_instance, message, with, returns, count)
  Type.assert(Sexp, receiver)
  Type.bool(any_instance)
  Type.assert(Sexp, message)
  Type.assert([NilClass, Sexp], with)
  Type.assert([NilClass, Sexp], returns)
  Type.assert([NilClass, Integer], count)
  @receiver = receiver
  @any_instance = any_instance
  @message = message
  @with = with
  @returns = returns
  @count = count
end

Instance Method Details

#to_rspec_expObject

Returns a Sexp representing an RSpec stub (allow) or message expectation (expect)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/minitest_to_rspec/rspec/stub.rb', line 27

def to_rspec_exp
  stub_chain = s(:call, nil, :receive, @message)
  unless @with.nil?
    stub_chain = s(:call, stub_chain, :with, @with)
  end
  unless @returns.nil?
    stub_chain = s(:call, stub_chain, :and_return, @returns)
  end
  unless @count.nil?
    stub_chain = s(:call, stub_chain, receive_count_method)
  end
  expect_allow = s(:call, nil, rspec_mocks_method, @receiver.dup)
  s(:call, expect_allow, :to, stub_chain)
end