Class: Transpec::Syntax::ShouldReceive::ExpectBaseRecordBuilder

Inherits:
RecordBuilder
  • Object
show all
Defined in:
lib/transpec/syntax/should_receive.rb

Direct Known Subclasses

AllowRecordBuilder, ExpectRecordBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RecordBuilder

build, #build

Constructor Details

#initialize(should_receive, negative_form_of_to) ⇒ ExpectBaseRecordBuilder

Returns a new instance of ExpectBaseRecordBuilder.



167
168
169
170
# File 'lib/transpec/syntax/should_receive.rb', line 167

def initialize(should_receive, negative_form_of_to)
  @should_receive = should_receive
  @negative_form_of_to = negative_form_of_to
end

Instance Attribute Details

#negative_form_of_to ⇒ Object (readonly)

Returns the value of attribute negative_form_of_to.



165
166
167
# File 'lib/transpec/syntax/should_receive.rb', line 165

def negative_form_of_to
  @negative_form_of_to
end

#should_receive ⇒ Object (readonly)

Returns the value of attribute should_receive.



165
166
167
# File 'lib/transpec/syntax/should_receive.rb', line 165

def should_receive
  @should_receive
end

Instance Method Details

#new_syntax ⇒ Object



185
186
187
188
189
190
191
192
193
# File 'lib/transpec/syntax/should_receive.rb', line 185

def new_syntax
  syntax = if should_receive.any_instance?
             "#{syntax_name}_any_instance_of(Klass)."
           else
             "#{syntax_name}(obj)."
           end
  syntax << (should_receive.positive? ? 'to' : negative_form_of_to)
  syntax << ' receive(:message)'
end

#old_syntax ⇒ Object



176
177
178
179
180
181
182
183
# File 'lib/transpec/syntax/should_receive.rb', line 176

def old_syntax
  syntax = if should_receive.any_instance?
             'Klass.any_instance.'
           else
             'obj.'
           end
  syntax << "#{should_receive.method_name}(:message)"
end

#syntax_name ⇒ Object



172
173
174
# File 'lib/transpec/syntax/should_receive.rb', line 172

def syntax_name
  fail NotImplementedError
end