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.



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

def initialize(have)
  @have = have
end

Instance Method Details

#converted_subjectObject



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/transpec/syntax/have.rb', line 218

def converted_subject
  if @have.subject_is_owner_of_collection?
    if @have.collection_accessor_is_private?
      "obj.send(#{@have.items_name.inspect}).#{@have.query_method}"
    else
      "obj.#{@have.items_name}.#{@have.query_method}"
    end
  else
    "collection.#{@have.default_query_method}"
  end
end

#converted_syntaxObject



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/transpec/syntax/have.rb', line 189

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



210
211
212
213
214
215
216
# File 'lib/transpec/syntax/have.rb', line 210

def original_items
  if @have.subject_is_owner_of_collection?
    @have.items_name
  else
    'items'
  end
end

#original_subjectObject



202
203
204
205
206
207
208
# File 'lib/transpec/syntax/have.rb', line 202

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

#original_syntaxObject



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/transpec/syntax/have.rb', line 176

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