Class: Transpec::Syntax::Have::HaveRecord
- Inherits:
-
Record
- Object
- Record
- Transpec::Syntax::Have::HaveRecord
show all
- Defined in:
- lib/transpec/syntax/have.rb
Instance Method Summary
collapse
Methods inherited from Record
#==, #hash, #to_s
Constructor Details
Returns a new instance of HaveRecord.
291
292
293
|
# File 'lib/transpec/syntax/have.rb', line 291
def initialize(have)
@have = have
end
|
Instance Method Details
#build_converted_subject(subject) ⇒ Object
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/transpec/syntax/have.rb', line 356
def build_converted_subject(subject)
subject << '.'
if @have.subject_is_owner_of_collection?
if @have.collection_accessor_is_private?
subject << "send(#{@have.collection_accessor.inspect}"
subject << ', ...' if @have.items_method_has_arguments?
subject << ')'
else
subject << "#{@have.collection_accessor}"
subject << '(...)' if @have.items_method_has_arguments?
end
subject << ".#{@have.query_method}"
else
subject << "#{@have.default_query_method}"
end
end
|
#build_expectation(subject, type) ⇒ Object
311
312
313
314
315
316
317
318
319
320
321
322
|
# File 'lib/transpec/syntax/have.rb', line 311
def build_expectation(subject, type)
case type
when :should
syntax = "#{subject}.should"
syntax << '_not' unless positive?
when :expect
syntax = "expect(#{subject})."
syntax << (positive? ? 'to' : 'not_to')
end
syntax
end
|
#converted_subject ⇒ Object
348
349
350
351
352
353
354
|
# File 'lib/transpec/syntax/have.rb', line 348
def converted_subject
if @have.subject_is_owner_of_collection?
build_converted_subject('obj')
else
build_converted_subject('collection')
end
end
|
#converted_syntax ⇒ Object
303
304
305
306
307
308
309
|
# File 'lib/transpec/syntax/have.rb', line 303
def converted_syntax
@converted_syntax ||= begin
type = @have.expectation.current_syntax_type
syntax = build_expectation(converted_subject, type)
syntax << " #{@have.build_replacement_matcher_source('n')}"
end
end
|
#original_items ⇒ Object
336
337
338
339
340
341
342
343
344
345
346
|
# File 'lib/transpec/syntax/have.rb', line 336
def original_items
if @have.subject_is_owner_of_collection?
if @have.items_method_has_arguments?
"#{@have.collection_accessor}(...)"
else
@have.collection_accessor
end
else
'items'
end
end
|
#original_subject ⇒ Object
328
329
330
331
332
333
334
|
# File 'lib/transpec/syntax/have.rb', line 328
def original_subject
if @have.subject_is_owner_of_collection?
'obj'
else
'collection'
end
end
|
#original_syntax ⇒ Object
295
296
297
298
299
300
301
|
# File 'lib/transpec/syntax/have.rb', line 295
def original_syntax
@original_syntax ||= begin
type = @have.expectation.class.snake_case_name.to_sym
syntax = build_expectation(original_subject, type)
syntax << " #{@have.have_method_name}(n).#{original_items}"
end
end
|
#positive? ⇒ Boolean
324
325
326
|
# File 'lib/transpec/syntax/have.rb', line 324
def positive?
@have.expectation.positive?
end
|