Class: Transpec::Syntax::Have::HaveRecord

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

Instance Method Summary collapse

Methods inherited from Record

#==, #hash, #to_s

Constructor Details

#initialize(have) ⇒ HaveRecord

Returns a new instance of HaveRecord.



251
252
253
# File 'lib/transpec/syntax/have.rb', line 251

def initialize(have)
  @have = have
end

Instance Method Details

#converted_subjectObject



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/transpec/syntax/have.rb', line 301

def converted_subject
  if @have.subject_is_owner_of_collection?
    subject = 'obj.'
    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
    "collection.#{@have.default_query_method}"
  end
end

#converted_syntaxObject



268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/transpec/syntax/have.rb', line 268

def converted_syntax
  @converted_syntax ||= begin
    syntax = case @have.expectation.current_syntax_type
             when :should
               "#{converted_subject}.should"
             when :expect
               "expect(#{converted_subject}).to"
             end

    syntax << " #{@have.replacement_matcher_source('n')}"
  end
end

#original_itemsObject



289
290
291
292
293
294
295
296
297
298
299
# File 'lib/transpec/syntax/have.rb', line 289

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_subjectObject



281
282
283
284
285
286
287
# File 'lib/transpec/syntax/have.rb', line 281

def original_subject
  if @have.subject_is_owner_of_collection?
    'obj'
  else
    'collection'
  end
end

#original_syntaxObject



255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/transpec/syntax/have.rb', line 255

def original_syntax
  @original_syntax ||= begin
    syntax = case @have.expectation
             when Should
               "#{original_subject}.should"
             when Expect
               "expect(#{original_subject}).to"
             end

    syntax << " #{@have.have_method_name}(n).#{original_items}"
  end
end