Class: Transpec::Syntax::OnelinerShould::HaveRecordBuilder
Instance Attribute Summary collapse
#have
Instance Method Summary
collapse
#annotation, #build_expectation, #build_new_subject, #new_owner_of_collection, #old_items, #old_subject, #positive?, #source_builder
build, #build
Constructor Details
#initialize(should, have, negative_form_of_to = nil) ⇒ HaveRecordBuilder
Returns a new instance of HaveRecordBuilder.
159
160
161
162
163
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 159
def initialize(should, have, negative_form_of_to = nil)
super(have)
@should = should
@negative_form_of_to = negative_form_of_to
end
|
Instance Attribute Details
Returns the value of attribute negative_form_of_to.
157
158
159
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 157
def negative_form_of_to
@negative_form_of_to
end
|
#should ⇒ Object
Returns the value of attribute should.
157
158
159
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 157
def should
@should
end
|
Instance Method Details
#new_description ⇒ Object
180
181
182
183
184
185
186
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 180
def new_description
if should.example.description?
"it '...' do"
else
"it '#{should.build_description('n')}' do"
end
end
|
#new_expectation ⇒ Object
188
189
190
191
192
193
194
195
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 188
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
197
198
199
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 197
def new_subject
build_new_subject('subject')
end
|
#new_syntax ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 171
def new_syntax
syntax = new_description
syntax << ' '
syntax << new_expectation
syntax << ' '
syntax << source_builder.replacement_matcher_source
syntax << ' end'
end
|
#old_syntax ⇒ Object
165
166
167
168
169
|
# File 'lib/transpec/syntax/oneliner_should.rb', line 165
def old_syntax
syntax = should.example.description? ? "it '...' do" : 'it {'
syntax << " #{should.method_name} #{have.method_name}(n).#{old_items} "
syntax << (should.example.description? ? 'end' : '}')
end
|