Class: Transpec::Syntax::OnelinerShould::OnelinerShouldHaveRecord

Inherits:
Have::HaveRecord show all
Defined in:
lib/transpec/syntax/oneliner_should.rb

Instance Method Summary collapse

Methods inherited from Have::HaveRecord

#build_converted_subject, #build_expectation, #original_items, #original_subject, #positive?

Methods inherited from Record

#==, #hash, #to_s

Constructor Details

#initialize(should, have, negative_form_of_to = nil) ⇒ OnelinerShouldHaveRecord

Returns a new instance of OnelinerShouldHaveRecord.



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

def initialize(should, have, negative_form_of_to = nil)
  @should = should
  @have = have
  @negative_form_of_to = negative_form_of_to
end

Instance Method Details

#converted_descriptionObject



191
192
193
194
195
196
197
# File 'lib/transpec/syntax/oneliner_should.rb', line 191

def converted_description
  if @should.example_has_description?
    "it '...' do"
  else
    "it '#{@should.build_description('n')}' do"
  end
end

#converted_expectationObject



199
200
201
202
203
204
205
206
# File 'lib/transpec/syntax/oneliner_should.rb', line 199

def converted_expectation
  case @should.current_syntax_type
  when :should
    "#{converted_subject}.#{@should.method_name}"
  when :expect
    "expect(#{converted_subject})." + (@should.positive? ? 'to' : @negative_form_of_to)
  end
end

#converted_subjectObject



208
209
210
# File 'lib/transpec/syntax/oneliner_should.rb', line 208

def converted_subject
  build_converted_subject('subject')
end

#converted_syntaxObject



180
181
182
183
184
185
186
187
188
189
# File 'lib/transpec/syntax/oneliner_should.rb', line 180

def converted_syntax
  @converted_syntax ||= begin
    syntax = converted_description
    syntax << ' '
    syntax << converted_expectation
    syntax << ' '
    syntax << @have.build_replacement_matcher_source('n')
    syntax << ' end'
  end
end

#original_syntaxObject



172
173
174
175
176
177
178
# File 'lib/transpec/syntax/oneliner_should.rb', line 172

def original_syntax
  @original_syntax ||= begin
    syntax = @should.example_has_description? ? "it '...' do" : 'it {'
    syntax << " #{@should.method_name} #{@have.have_method_name}(n).#{original_items} "
    syntax << (@should.example_has_description? ? 'end' : '}')
  end
end