Class: Transpec::Syntax::OnelinerShould::HaveRecordBuilder
Instance Method Summary
collapse
#annotation, #build_expectation, #build_new_subject, #new_owner_of_collection, #old_items, #old_subject, #positive?, #source_builder
build, #build, param_names
Instance Method Details
#had_description? ⇒ 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
194
195
196
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 194
def has_description? !should.example.nil?
end
|
#new_description ⇒ Object
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_expectation ⇒ Object
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_subject ⇒ Object
185
186
187
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 185
def new_subject
build_new_subject('subject')
end
|
#new_syntax ⇒ Object
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_syntax ⇒ Object
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
|