Class: Transpec::Syntax::OnelinerShould::HaveRecordBuilder

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

Instance Method Summary collapse

Methods inherited from Have::RecordBuilder

#annotation, #build_expectation, #build_new_subject, #new_owner_of_collection, #old_items, #old_subject, #positive?, #source_builder

Methods inherited from RecordBuilder

build, #build, param_names

Instance Method Details

#had_description?Boolean

Returns:

  • (Boolean)


189
190
191
192
# File 'lib/transpec/syntax/oneliner_should.rb', line 189

def had_description?
  return false unless should.example
  should.example.description?
end

#has_description?Boolean

rubocop:disable PredicateName

Returns:

  • (Boolean)


194
195
196
# File 'lib/transpec/syntax/oneliner_should.rb', line 194

def has_description? # rubocop:disable PredicateName
  !should.example.nil?
end

#new_descriptionObject



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/transpec/syntax/oneliner_should.rb', line 164

def new_description
  if has_description?
    if had_description?
      "it '...' do"
    else
      "it '#{should.build_description('n')}' do"
    end
  else
    'it {'
  end
end

#new_expectationObject



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

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

#new_subjectObject



185
186
187
# File 'lib/transpec/syntax/oneliner_should.rb', line 185

def new_subject
  build_new_subject('subject')
end

#new_syntaxObject



154
155
156
157
158
159
160
161
162
# File 'lib/transpec/syntax/oneliner_should.rb', line 154

def new_syntax
  syntax = new_description
  syntax << ' '
  syntax << new_expectation
  syntax << ' '
  syntax << source_builder.replacement_matcher_source
  syntax << ' '
  syntax << (has_description? ? 'end' : '}')
end

#old_syntaxObject



148
149
150
151
152
# File 'lib/transpec/syntax/oneliner_should.rb', line 148

def old_syntax
  syntax = had_description? ? "it '...' do" : 'it {'
  syntax << " #{should.method_name} #{have.method_name}(n).#{old_items} "
  syntax << (had_description? ? 'end' : '}')
end