Class: Transpec::Syntax::Have::RecordBuilder
Instance Method Summary
collapse
build, #build, param_names
Instance Method Details
#annotation ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 11
def annotation
return @annotation if instance_variable_defined?(:@annotation)
@annotation = if have.accurate_conversion?
nil
else
AccuracyAnnotation.new(have.matcher_range)
end
end
|
#build_expectation(subject, type) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 33
def build_expectation(subject, type)
case type
when :should
syntax = "#{subject}.should"
syntax << '_not' unless positive?
when :expect
syntax = "expect(#{subject})."
syntax << (positive? ? 'to' : 'not_to')
end
syntax
end
|
#build_new_subject(subject) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 78
def build_new_subject(subject)
if have.subject_is_owner_of_collection?
new_owner_of_collection(subject)
else
subject << ".#{have.default_query_method}"
end
end
|
#new_owner_of_collection(subject) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 86
def new_owner_of_collection(subject)
subject << '.'
if have.collection_accessor_is_private?
subject << "send(#{have.collection_accessor.inspect}"
subject << ', ...' if have.items_method_has_arguments?
subject << ')'
else
subject << "#{have.collection_accessor}"
subject << '(...)' if have.items_method_has_arguments?
end
subject << ".#{have.query_method}"
end
|
#new_subject ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 70
def new_subject
if have.subject_is_owner_of_collection?
build_new_subject('obj')
else
build_new_subject('collection')
end
end
|
#new_syntax ⇒ Object
27
28
29
30
31
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 27
def new_syntax
type = have.expectation.current_syntax_type
syntax = build_expectation(new_subject, type)
syntax << " #{source_builder.replacement_matcher_source}"
end
|
#old_items ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 58
def old_items
if have.subject_is_owner_of_collection?
if have.items_method_has_arguments?
"#{have.collection_accessor}(...)"
else
have.collection_accessor
end
else
'items'
end
end
|
#old_subject ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 50
def old_subject
if have.subject_is_owner_of_collection?
'obj'
else
'collection'
end
end
|
#old_syntax ⇒ Object
21
22
23
24
25
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 21
def old_syntax
type = have.expectation.class.snake_case_name.to_sym
syntax = build_expectation(old_subject, type)
syntax << " #{have.method_name}(n).#{old_items}"
end
|
#positive? ⇒ Boolean
46
47
48
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 46
def positive?
have.expectation.positive?
end
|
#source_builder ⇒ Object
101
102
103
|
# File 'lib/transpec/syntax/have/record_builder.rb', line 101
def source_builder
@source_builder ||= SourceBuilder.new(have, 'n')
end
|