transpec 2.2.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/transpec/conversion_error.rb +5 -5
- data/lib/transpec/converter.rb +14 -12
- data/lib/transpec/record.rb +88 -31
- data/lib/transpec/report.rb +19 -11
- data/lib/transpec/rspec_version.rb +9 -0
- data/lib/transpec/syntax/be_boolean.rb +2 -2
- data/lib/transpec/syntax/be_close.rb +1 -1
- data/lib/transpec/syntax/current_example.rb +35 -17
- data/lib/transpec/syntax/double.rb +1 -1
- data/lib/transpec/syntax/example.rb +0 -4
- data/lib/transpec/syntax/example_group.rb +11 -11
- data/lib/transpec/syntax/have/{have_record.rb → record_builder.rb} +15 -17
- data/lib/transpec/syntax/have.rb +2 -2
- data/lib/transpec/syntax/hook.rb +3 -3
- data/lib/transpec/syntax/its.rb +25 -17
- data/lib/transpec/syntax/matcher_definition.rb +1 -2
- data/lib/transpec/syntax/method_stub.rb +44 -51
- data/lib/transpec/syntax/mixin/any_instance_block.rb +8 -6
- data/lib/transpec/syntax/mixin/useless_and_return.rb +9 -7
- data/lib/transpec/syntax/oneliner_should.rb +29 -27
- data/lib/transpec/syntax/operator.rb +3 -3
- data/lib/transpec/syntax/pending.rb +0 -4
- data/lib/transpec/syntax/raise_error.rb +35 -15
- data/lib/transpec/syntax/receive.rb +6 -6
- data/lib/transpec/syntax/rspec_configure/config_modification.rb +39 -5
- data/lib/transpec/syntax/rspec_configure/framework.rb +27 -7
- data/lib/transpec/syntax/rspec_configure/mocks.rb +2 -2
- data/lib/transpec/syntax/rspec_configure.rb +35 -4
- data/lib/transpec/syntax/should.rb +35 -20
- data/lib/transpec/syntax/should_receive.rb +30 -27
- data/lib/transpec/syntax.rb +10 -0
- data/lib/transpec/version.rb +2 -2
- data/spec/integration/configuration_modification_spec.rb +43 -3
- data/spec/transpec/record_spec.rb +113 -18
- data/spec/transpec/report_spec.rb +15 -6
- data/spec/transpec/rspec_version_spec.rb +5 -0
- data/spec/transpec/syntax/be_boolean_spec.rb +10 -10
- data/spec/transpec/syntax/be_close_spec.rb +2 -2
- data/spec/transpec/syntax/current_example_spec.rb +6 -6
- data/spec/transpec/syntax/double_spec.rb +2 -2
- data/spec/transpec/syntax/example_group_spec.rb +4 -4
- data/spec/transpec/syntax/example_spec.rb +8 -8
- data/spec/transpec/syntax/have_spec.rb +44 -44
- data/spec/transpec/syntax/hook_spec.rb +8 -8
- data/spec/transpec/syntax/its_spec.rb +16 -16
- data/spec/transpec/syntax/matcher_definition_spec.rb +2 -2
- data/spec/transpec/syntax/method_stub_spec.rb +36 -36
- data/spec/transpec/syntax/oneliner_should_spec.rb +26 -26
- data/spec/transpec/syntax/operator_spec.rb +18 -18
- data/spec/transpec/syntax/pending_spec.rb +6 -6
- data/spec/transpec/syntax/raise_error_spec.rb +10 -10
- data/spec/transpec/syntax/receive_spec.rb +20 -20
- data/spec/transpec/syntax/rspec_configure_spec.rb +202 -18
- data/spec/transpec/syntax/should_receive_spec.rb +30 -30
- data/spec/transpec/syntax/should_spec.rb +8 -8
- data/tasks/fixtures/mail/2.99.0/COMMIT_EDITMSG +1 -1
- data/tasks/fixtures/mail/3.0.0/COMMIT_EDITMSG +5 -2
- data/tasks/fixtures/twitter/2.99.0/COMMIT_EDITMSG +1 -1
- data/tasks/fixtures/twitter/3.0.0/COMMIT_EDITMSG +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cc32f4f45ab036ddecaefb46245014a4713fdee
|
4
|
+
data.tar.gz: 2b7feec59ef424cb3df9d47145683fcc6c496b9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b53e41a17861208c396e6955152123dca5a623041265987c8f03caf3f3bb14fb28ddaabcd1f46dad918a477ad499e155e801e042ab3b6464ccc46d0ebdb7f361
|
7
|
+
data.tar.gz: 3b3cf2d94a9a6adfd671235d639ae65a2cf8c8887acccb28b6b4eee9c9dabd266a84d195f680b425410685f466a3e726f07610e9045750b6e3377427044d3002
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v2.3.0
|
6
|
+
|
7
|
+
* Report configuration modifications of `RSpec.configure` in the final summary.
|
8
|
+
* Support conversion of configuration options `backtrace_clean_patterns`, `backtrace_clean_patterns=`, `color_enabled=`, `output`, `output=`, `out`, `out=`, `filename_pattern`, `filename_pattern=`, `backtrace_cleaner`, `backtrace_cleaner=`, `color?` and `warnings`.
|
9
|
+
|
5
10
|
## v2.2.5
|
6
11
|
|
7
12
|
* Fix invalid conversion of `unstub` without parentheses (`obj.unstub :message`). ([#74](https://github.com/yujinakayama/transpec/pull/74))
|
@@ -8,16 +8,16 @@ module Transpec
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class ContextError < ConversionError
|
11
|
-
def initialize(
|
12
|
-
message = build_message(
|
11
|
+
def initialize(old_syntax, new_syntax, source_range)
|
12
|
+
message = build_message(old_syntax, new_syntax)
|
13
13
|
super(message, source_range)
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def build_message(
|
19
|
-
"Cannot convert #{
|
20
|
-
"since #{
|
18
|
+
def build_message(old_syntax, new_syntax)
|
19
|
+
"Cannot convert #{old_syntax} into #{new_syntax} " \
|
20
|
+
"since #{new_syntax} is not available in the context."
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/transpec/converter.rb
CHANGED
@@ -165,21 +165,23 @@ module Transpec
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def process_rspec_configure(rspec_configure)
|
168
|
-
|
168
|
+
rspec_configure.convert_deprecated_options!(rspec_version)
|
169
169
|
|
170
|
-
if
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
if spec_suite.main_rspec_configure_node?(rspec_configure.node)
|
171
|
+
if rspec_version.non_monkey_patch_example_group_available? &&
|
172
|
+
config.convert_example_group?
|
173
|
+
rspec_configure.expose_dsl_globally = false
|
174
|
+
end
|
174
175
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
176
|
+
if need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
|
177
|
+
should_yield = config.add_receiver_arg_to_any_instance_implementation_block?
|
178
|
+
rspec_configure.mocks.yield_receiver_to_any_instance_implementation_blocks = should_yield
|
179
|
+
end
|
179
180
|
|
180
|
-
|
181
|
-
|
182
|
-
|
181
|
+
if rspec_version.implicit_spec_type_disablement_available? &&
|
182
|
+
!config.add_explicit_type_metadata_to_example_group?
|
183
|
+
rspec_configure.infer_spec_type_from_file_location!
|
184
|
+
end
|
183
185
|
end
|
184
186
|
end
|
185
187
|
|
data/lib/transpec/record.rb
CHANGED
@@ -4,66 +4,123 @@ require 'transpec/annotatable'
|
|
4
4
|
|
5
5
|
module Transpec
|
6
6
|
class Record
|
7
|
-
|
8
|
-
:original_syntax,
|
9
|
-
:original_syntax_type,
|
10
|
-
:converted_syntax,
|
11
|
-
:converted_syntax_type
|
12
|
-
]
|
7
|
+
include Comparable
|
13
8
|
|
14
|
-
|
9
|
+
TYPES = [:conversion, :addition, :removal, :modification]
|
10
|
+
COMPARISON_ATTRIBUTES = [:type_sort_key, :old_syntax, :new_syntax].freeze
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
attr_reader :old_syntax_type, :new_syntax_type, :annotation
|
13
|
+
|
14
|
+
def initialize(old_syntax, new_syntax, options = {})
|
15
|
+
# Keep these syntax data as symbols for:
|
16
|
+
# * Better memory footprint
|
17
|
+
# * Better summarizing performance in Report
|
18
|
+
@old_syntax_type = old_syntax && old_syntax.to_sym
|
19
|
+
@new_syntax_type = new_syntax && new_syntax.to_sym
|
20
|
+
|
21
|
+
@type = options[:type]
|
22
|
+
@annotation = options[:annotation]
|
21
23
|
|
22
|
-
|
23
|
-
original_syntax_type.to_s
|
24
|
+
fail ArgumentError, "Invalid type: #{type}" unless TYPES.include?(type)
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
|
27
|
+
def type
|
28
|
+
@type ||= if old_syntax_type && new_syntax_type
|
29
|
+
:conversion
|
30
|
+
elsif new_syntax_type
|
31
|
+
:addition
|
32
|
+
else
|
33
|
+
:removal
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
|
-
def
|
31
|
-
|
37
|
+
def old_syntax
|
38
|
+
old_syntax_type && old_syntax_type.to_s
|
32
39
|
end
|
33
40
|
|
34
|
-
def
|
35
|
-
|
41
|
+
def new_syntax
|
42
|
+
new_syntax_type && new_syntax_type.to_s
|
36
43
|
end
|
37
44
|
|
38
45
|
def ==(other)
|
39
46
|
self.class == other.class &&
|
40
|
-
|
41
|
-
|
47
|
+
old_syntax_type == other.old_syntax_type &&
|
48
|
+
new_syntax_type == other.new_syntax_type
|
42
49
|
end
|
43
50
|
|
44
51
|
alias_method :eql?, :==
|
45
52
|
|
46
53
|
def hash
|
47
|
-
|
54
|
+
old_syntax_type.hash ^ new_syntax_type.hash
|
48
55
|
end
|
49
56
|
|
50
57
|
def to_s
|
51
|
-
|
58
|
+
string = type.to_s.capitalize
|
59
|
+
|
60
|
+
string << case type
|
61
|
+
when :conversion, :modification
|
62
|
+
" from `#{old_syntax_type}` to `#{new_syntax_type}`"
|
63
|
+
when :addition
|
64
|
+
" of `#{new_syntax_type}`"
|
65
|
+
when :removal
|
66
|
+
" of `#{old_syntax_type}`"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def <=>(other)
|
71
|
+
COMPARISON_ATTRIBUTES.each do |attribute|
|
72
|
+
result = send(attribute) <=> other.send(attribute)
|
73
|
+
return result unless result == 0
|
74
|
+
end
|
75
|
+
0
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def type_sort_key
|
81
|
+
case type
|
82
|
+
when :conversion then 1
|
83
|
+
when :modification then 2
|
84
|
+
when :addition then 3
|
85
|
+
when :removal then 4
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# This class is intended to be inherited to build complex record.
|
91
|
+
# The reasons why you should inherit this class rather than Record are:
|
92
|
+
# * You need to care about String and Symbol around Record#old_syntax and #new_syntax.
|
93
|
+
# * All record instances are kept in a Report until the end of Transpec process.
|
94
|
+
# This mean that if a custom record keeps a syntax object as an ivar,
|
95
|
+
# the AST kept by the syntax object won't be GCed.
|
96
|
+
class RecordBuilder
|
97
|
+
def self.build(*args)
|
98
|
+
new(*args).build
|
99
|
+
end
|
100
|
+
|
101
|
+
def build
|
102
|
+
Record.new(old_syntax, new_syntax, { type: type, annotation: annotation })
|
52
103
|
end
|
53
104
|
|
54
105
|
private
|
55
106
|
|
56
|
-
def
|
57
|
-
|
107
|
+
def initialize(*)
|
108
|
+
end
|
109
|
+
|
110
|
+
def old_syntax
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
|
114
|
+
def new_syntax
|
115
|
+
nil
|
58
116
|
end
|
59
117
|
|
60
|
-
def
|
61
|
-
|
118
|
+
def type
|
119
|
+
nil
|
62
120
|
end
|
63
121
|
|
64
|
-
def
|
65
|
-
|
66
|
-
fail "Do not override Record##{method_name}."
|
122
|
+
def annotation
|
123
|
+
nil
|
67
124
|
end
|
68
125
|
end
|
69
126
|
|
data/lib/transpec/report.rb
CHANGED
@@ -27,7 +27,7 @@ module Transpec
|
|
27
27
|
end
|
28
28
|
|
29
29
|
sorted_record_counts = record_counts.sort_by do |record, count|
|
30
|
-
[-count, record
|
30
|
+
[-count, record]
|
31
31
|
end
|
32
32
|
|
33
33
|
Hash[sorted_record_counts]
|
@@ -85,16 +85,24 @@ module Transpec
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def format_record(record, count, bullet = nil)
|
88
|
-
entry_prefix = bullet ? bullet
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
88
|
+
entry_prefix = bullet ? "#{bullet} " : ''
|
89
|
+
text = entry_prefix + colorize(pluralize(count, record.type), :cyan) + "\n"
|
90
|
+
|
91
|
+
justification = entry_prefix.length + 6
|
92
|
+
|
93
|
+
case record.type
|
94
|
+
when :conversion
|
95
|
+
text << labeled_line('from', record.old_syntax, justification)
|
96
|
+
text << labeled_line('to', record.new_syntax, justification)
|
97
|
+
when :addition
|
98
|
+
text << labeled_line('of', record.new_syntax, justification)
|
99
|
+
when :removal
|
100
|
+
text << labeled_line('of', record.old_syntax, justification)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def labeled_line(label, content, justification)
|
105
|
+
colorize("#{label.rjust(justification)}: ", :cyan) + content + "\n"
|
98
106
|
end
|
99
107
|
|
100
108
|
def conversion_incomplete_warning_stats(color)
|
@@ -43,11 +43,20 @@ module Transpec
|
|
43
43
|
|
44
44
|
define_feature :be_truthy, '2.99.0.beta1'
|
45
45
|
define_feature :yielded_example, '2.99.0.beta1'
|
46
|
+
define_feature :config_output_stream, '2.99.0.beta1'
|
46
47
|
define_feature :yielding_receiver_to_any_instance_implementation_block, '2.99.0.beta1'
|
47
48
|
|
48
49
|
define_feature :oneliner_is_expected, '2.99.0.beta2', except: '3.0.0.beta1'
|
49
50
|
define_feature :skip, '2.99.0.beta2', except: '3.0.0.beta1'
|
50
51
|
|
52
|
+
define_feature :config_pattern, '2.99.0.rc1',
|
53
|
+
except: ['3.0.0.beta1', '3.0.0.beta2']
|
54
|
+
define_feature :config_backtrace_formatter, '2.99.0.rc1',
|
55
|
+
except: ['3.0.0.beta1', '3.0.0.beta2']
|
56
|
+
define_feature :config_predicate_color_enabled, '2.99.0.rc1',
|
57
|
+
except: ['3.0.0.beta1', '3.0.0.beta2']
|
58
|
+
define_feature :config_predicate_warnings, '2.99.0.rc1',
|
59
|
+
except: ['3.0.0.beta1', '3.0.0.beta2']
|
51
60
|
define_feature :implicit_spec_type_disablement, '2.99.0.rc1',
|
52
61
|
except: ['3.0.0.beta1', '3.0.0.beta2']
|
53
62
|
|
@@ -28,13 +28,7 @@ module Transpec
|
|
28
28
|
replace(selector_range, 'RSpec.current_example')
|
29
29
|
end
|
30
30
|
|
31
|
-
add_record
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def block_has_argument?
|
37
|
-
block_arg_node || block_node.metadata[:added_example_block_arg]
|
31
|
+
add_record(RecordBuilder.build(self))
|
38
32
|
end
|
39
33
|
|
40
34
|
def block_node
|
@@ -51,6 +45,12 @@ module Transpec
|
|
51
45
|
method_name_of_block_node(block_node)
|
52
46
|
end
|
53
47
|
|
48
|
+
private
|
49
|
+
|
50
|
+
def block_has_argument?
|
51
|
+
block_arg_node || block_node.metadata[:added_example_block_arg]
|
52
|
+
end
|
53
|
+
|
54
54
|
def block_arg_node
|
55
55
|
args_node = block_node.children[1]
|
56
56
|
args_node.children.first
|
@@ -69,18 +69,36 @@ module Transpec
|
|
69
69
|
send_node.children[1]
|
70
70
|
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
original_syntax = 'def helper_method example; end'
|
80
|
-
converted_syntax = 'def helper_method RSpec.current_example; end'
|
72
|
+
class RecordBuilder < Transpec::RecordBuilder
|
73
|
+
include RSpecDSL
|
74
|
+
|
75
|
+
attr_reader :current_example
|
76
|
+
|
77
|
+
def initialize(current_example)
|
78
|
+
@current_example = current_example
|
81
79
|
end
|
82
80
|
|
83
|
-
|
81
|
+
def old_syntax
|
82
|
+
if current_example.block_node
|
83
|
+
"#{base_dsl} { example }"
|
84
|
+
else
|
85
|
+
'def helper_method example; end'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def new_syntax
|
90
|
+
if current_example.block_node
|
91
|
+
"#{base_dsl} { |example| example }"
|
92
|
+
else
|
93
|
+
'def helper_method RSpec.current_example; end'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def base_dsl
|
98
|
+
dsl = "#{current_example.block_method_name}"
|
99
|
+
dsl << '(:name)' if HELPER_METHODS.include?(current_example.block_method_name)
|
100
|
+
dsl
|
101
|
+
end
|
84
102
|
end
|
85
103
|
end
|
86
104
|
end
|
@@ -39,7 +39,7 @@ module Transpec
|
|
39
39
|
def convert_to_non_monkey_patch!
|
40
40
|
return if receiver_node
|
41
41
|
insert_before(expression_range, 'RSpec.')
|
42
|
-
|
42
|
+
add_record(NonMonkeyPatchRecordBuilder.build(self))
|
43
43
|
end
|
44
44
|
|
45
45
|
def add_explicit_type_metadata!
|
@@ -59,7 +59,7 @@ module Transpec
|
|
59
59
|
|
60
60
|
insert_after(arg_node.loc.expression, code)
|
61
61
|
|
62
|
-
|
62
|
+
add_record(ExplicitTypeMetadataRecordBuilder.build(self))
|
63
63
|
end
|
64
64
|
|
65
65
|
def implicit_type_metadata
|
@@ -96,18 +96,18 @@ module Transpec
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
class
|
99
|
+
class NonMonkeyPatchRecordBuilder < RecordBuilder
|
100
100
|
attr_reader :example_group
|
101
101
|
|
102
102
|
def initialize(example_group)
|
103
103
|
@example_group = example_group
|
104
104
|
end
|
105
105
|
|
106
|
-
def
|
106
|
+
def old_syntax
|
107
107
|
base_syntax
|
108
108
|
end
|
109
109
|
|
110
|
-
def
|
110
|
+
def new_syntax
|
111
111
|
"RSpec.#{base_syntax}"
|
112
112
|
end
|
113
113
|
|
@@ -116,22 +116,22 @@ module Transpec
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
class
|
119
|
+
class ExplicitTypeMetadataRecordBuilder < RecordBuilder
|
120
120
|
attr_reader :example_group
|
121
121
|
|
122
122
|
def initialize(example_group)
|
123
123
|
@example_group = example_group
|
124
124
|
end
|
125
125
|
|
126
|
-
def
|
127
|
-
"describe 'some #{
|
126
|
+
def old_syntax
|
127
|
+
"describe 'some #{spec_type}' { }"
|
128
128
|
end
|
129
129
|
|
130
|
-
def
|
131
|
-
"describe 'some #{
|
130
|
+
def new_syntax
|
131
|
+
"describe 'some #{spec_type}', :type => #{spec_type.inspect} { }"
|
132
132
|
end
|
133
133
|
|
134
|
-
def
|
134
|
+
def spec_type
|
135
135
|
example_group.implicit_type_metadata
|
136
136
|
end
|
137
137
|
end
|
@@ -5,7 +5,7 @@ require 'transpec/syntax/have'
|
|
5
5
|
module Transpec
|
6
6
|
class Syntax
|
7
7
|
class Have
|
8
|
-
class
|
8
|
+
class RecordBuilder < Transpec::RecordBuilder
|
9
9
|
attr_reader :have
|
10
10
|
|
11
11
|
def initialize(have)
|
@@ -22,17 +22,15 @@ module Transpec
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
def build_original_syntax
|
25
|
+
def old_syntax
|
28
26
|
type = have.expectation.class.snake_case_name.to_sym
|
29
|
-
syntax = build_expectation(
|
30
|
-
syntax << " #{have.method_name}(n).#{
|
27
|
+
syntax = build_expectation(old_subject, type)
|
28
|
+
syntax << " #{have.method_name}(n).#{old_items}"
|
31
29
|
end
|
32
30
|
|
33
|
-
def
|
31
|
+
def new_syntax
|
34
32
|
type = have.expectation.current_syntax_type
|
35
|
-
syntax = build_expectation(
|
33
|
+
syntax = build_expectation(new_subject, type)
|
36
34
|
syntax << " #{source_builder.replacement_matcher_source}"
|
37
35
|
end
|
38
36
|
|
@@ -53,7 +51,7 @@ module Transpec
|
|
53
51
|
have.expectation.positive?
|
54
52
|
end
|
55
53
|
|
56
|
-
def
|
54
|
+
def old_subject
|
57
55
|
if have.subject_is_owner_of_collection?
|
58
56
|
'obj'
|
59
57
|
else
|
@@ -61,7 +59,7 @@ module Transpec
|
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
64
|
-
def
|
62
|
+
def old_items
|
65
63
|
if have.subject_is_owner_of_collection?
|
66
64
|
if have.items_method_has_arguments?
|
67
65
|
"#{have.collection_accessor}(...)"
|
@@ -73,23 +71,23 @@ module Transpec
|
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
76
|
-
def
|
77
|
-
if
|
78
|
-
|
74
|
+
def new_subject
|
75
|
+
if have.subject_is_owner_of_collection?
|
76
|
+
build_new_subject('obj')
|
79
77
|
else
|
80
|
-
|
78
|
+
build_new_subject('collection')
|
81
79
|
end
|
82
80
|
end
|
83
81
|
|
84
|
-
def
|
82
|
+
def build_new_subject(subject)
|
85
83
|
if have.subject_is_owner_of_collection?
|
86
|
-
|
84
|
+
new_owner_of_collection(subject)
|
87
85
|
else
|
88
86
|
subject << ".#{have.default_query_method}"
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
|
-
def
|
90
|
+
def new_owner_of_collection(subject)
|
93
91
|
subject << '.'
|
94
92
|
|
95
93
|
if have.collection_accessor_is_private?
|
data/lib/transpec/syntax/have.rb
CHANGED
@@ -8,8 +8,8 @@ module Transpec
|
|
8
8
|
class Syntax
|
9
9
|
class Have < Syntax
|
10
10
|
require 'transpec/syntax/have/dynamic_analysis'
|
11
|
+
require 'transpec/syntax/have/record_builder'
|
11
12
|
require 'transpec/syntax/have/source_builder'
|
12
|
-
require 'transpec/syntax/have/have_record'
|
13
13
|
|
14
14
|
include Mixin::Send, Mixin::OwnedMatcher, DynamicAnalysis
|
15
15
|
|
@@ -132,7 +132,7 @@ module Transpec
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def add_record
|
135
|
-
|
135
|
+
super(Have::RecordBuilder.build(self))
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
data/lib/transpec/syntax/hook.rb
CHANGED
@@ -36,9 +36,9 @@ module Transpec
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def add_record
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
old_syntax = "#{method_name}(#{scope_name.inspect}) { }"
|
40
|
+
new_syntax = "#{method_name}(#{replacement_scope_name.inspect}) { }"
|
41
|
+
super(old_syntax, new_syntax)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
data/lib/transpec/syntax/its.rb
CHANGED
@@ -120,23 +120,7 @@ module Transpec
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def add_record
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
def original_syntax
|
127
|
-
if attribute_expression.brackets?
|
128
|
-
'its([:key]) { }'
|
129
|
-
else
|
130
|
-
'its(:attr) { }'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def converted_syntax
|
135
|
-
if attribute_expression.brackets?
|
136
|
-
"describe '[:key]' do subject { super()[:key] }; it { } end"
|
137
|
-
else
|
138
|
-
"describe '#attr' do subject { super().attr }; it { } end"
|
139
|
-
end
|
123
|
+
super(RecordBuilder.build(self))
|
140
124
|
end
|
141
125
|
|
142
126
|
class AttributeExpression
|
@@ -196,6 +180,30 @@ module Transpec
|
|
196
180
|
end
|
197
181
|
|
198
182
|
Attribute = Struct.new(:selector, :description)
|
183
|
+
|
184
|
+
class RecordBuilder < Transpec::RecordBuilder
|
185
|
+
attr_reader :its
|
186
|
+
|
187
|
+
def initialize(its)
|
188
|
+
@its = its
|
189
|
+
end
|
190
|
+
|
191
|
+
def old_syntax
|
192
|
+
if its.attribute_expression.brackets?
|
193
|
+
'its([:key]) { }'
|
194
|
+
else
|
195
|
+
'its(:attr) { }'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def new_syntax
|
200
|
+
if its.attribute_expression.brackets?
|
201
|
+
"describe '[:key]' do subject { super()[:key] }; it { } end"
|
202
|
+
else
|
203
|
+
"describe '#attr' do subject { super().attr }; it { } end"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
199
207
|
end
|
200
208
|
end
|
201
209
|
end
|