transpec 2.3.1 → 2.3.2

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile +0 -2
  5. data/README.md +13 -5
  6. data/README.md.erb +13 -5
  7. data/lib/transpec/ast/node.rb +2 -75
  8. data/lib/transpec/directory_cloner.rb +53 -0
  9. data/lib/transpec/dynamic_analyzer.rb +10 -50
  10. data/lib/transpec/record.rb +10 -1
  11. data/lib/transpec/rspec_dsl.rb +0 -2
  12. data/lib/transpec/static_context_inspector.rb +3 -3
  13. data/lib/transpec/syntax/current_example.rb +3 -8
  14. data/lib/transpec/syntax/example.rb +1 -1
  15. data/lib/transpec/syntax/example_group.rb +15 -11
  16. data/lib/transpec/syntax/have/dynamic_analysis.rb +0 -2
  17. data/lib/transpec/syntax/have/record_builder.rb +1 -5
  18. data/lib/transpec/syntax/its.rb +2 -6
  19. data/lib/transpec/syntax/method_stub.rb +6 -21
  20. data/lib/transpec/syntax/mixin/any_instance_block.rb +1 -5
  21. data/lib/transpec/syntax/mixin/expect_base.rb +1 -1
  22. data/lib/transpec/syntax/mixin/metadata.rb +10 -1
  23. data/lib/transpec/syntax/mixin/should_base.rb +4 -0
  24. data/lib/transpec/syntax/mixin/useless_and_return.rb +1 -5
  25. data/lib/transpec/syntax/oneliner_should.rb +4 -23
  26. data/lib/transpec/syntax/operator.rb +1 -1
  27. data/lib/transpec/syntax/raise_error.rb +1 -5
  28. data/lib/transpec/syntax/rspec_configure/config_modification.rb +2 -3
  29. data/lib/transpec/syntax/rspec_configure/framework.rb +2 -3
  30. data/lib/transpec/syntax/rspec_configure/mocks.rb +0 -4
  31. data/lib/transpec/syntax/rspec_configure.rb +0 -4
  32. data/lib/transpec/syntax/should.rb +1 -13
  33. data/lib/transpec/syntax/should_receive.rb +2 -11
  34. data/lib/transpec/syntax.rb +1 -1
  35. data/lib/transpec/util.rb +2 -3
  36. data/lib/transpec/version.rb +1 -1
  37. data/spec/transpec/directory_cloner_spec.rb +74 -0
  38. data/spec/transpec/dynamic_analyzer_spec.rb +0 -57
  39. data/spec/transpec/spec_suite_spec.rb +2 -2
  40. data/spec/transpec/static_context_inspector_spec.rb +0 -7
  41. data/spec/transpec/syntax/current_example_spec.rb +3 -6
  42. data/spec/transpec/syntax/double_spec.rb +3 -6
  43. data/spec/transpec/syntax/example_group_spec.rb +96 -1
  44. data/spec/transpec/syntax/example_spec.rb +3 -5
  45. data/spec/transpec/syntax/expect_spec.rb +3 -6
  46. data/spec/transpec/syntax/have_spec.rb +3 -5
  47. data/spec/transpec/syntax/its_spec.rb +3 -5
  48. data/spec/transpec/syntax/method_stub_spec.rb +3 -6
  49. data/spec/transpec/syntax/oneliner_should_spec.rb +3 -6
  50. data/spec/transpec/syntax/pending_spec.rb +3 -5
  51. data/transpec.gemspec +2 -1
  52. metadata +27 -6
  53. data/spec/transpec/ast/node_spec.rb +0 -323
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c90c3e229024fe5588256af42c0ac3fdc30f146a
4
- data.tar.gz: 3d786286cac9c9298c9aaa073288ad2bb1e83a50
3
+ metadata.gz: e2ca68d2ec61ab33ba2a0111a03728a08925606d
4
+ data.tar.gz: df0d66e1266197c0fe17a3533cafa4a6cd1649ee
5
5
  SHA512:
6
- metadata.gz: 28e8ac6dacd5834196381b9510bd3b4d8394f084eedfb584407a7a6234d68cd3fe6da89957a7b7be2f7481c0f3ab0aa43e25655554885bd3258a626faf59f793
7
- data.tar.gz: ee3405cacf7e33bcfe378ebc55af52e9b69d4e2041bc78cdbb8e363706ae0b9011f65db64c6a8b94ea69a5291b0aa9e74c0827fb50254baa974a6d3d19d47c7f
6
+ metadata.gz: 7221ef0ade502c3ab43987fc1fcb24c671795f840ebe4e29d073803f417592e616dc97130a12e8bcd4b75c78fb21b1b693bd7630522577b084c090747656092d
7
+ data.tar.gz: 5aa6b286c235b51e47ab7bba1ac8f26bc25a26e85e3632f3305bdcd0f4c12bc39e04096fe4ee76b71bcc47652c78b53810e6a4a3c178bee42867bc425f77e2ec
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v2.3.2
6
+
7
+ * Fix a bug where explicit spec type metadata are added to wrong position when the `describe` has multiple non-metadata arguments (e.g. `describe Something, '#some_method' { }`). ([#77](https://github.com/yujinakayama/transpec/issues/77))
8
+
5
9
  ## v2.3.1
6
10
 
7
11
  * Remove conversion support for non-existent configuration option `backtrace_cleaner=`.
data/CONTRIBUTING.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Contributing
2
2
 
3
- If you're going to report an issue or submit a pull requrest, please follow these guidelines.
3
+ If you're going to report an issue or submit a pull request, please follow these guidelines.
4
4
 
5
5
  ## Reporting an Issue
6
6
 
data/Gemfile CHANGED
@@ -2,8 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rubocop', github: 'bbatsov/rubocop' if RUBY_VERSION.start_with?('2.2')
6
-
7
5
  group :test do
8
6
  gem 'coveralls', '~> 0.6'
9
7
  gem 'simplecov-rcov', '~> 0.2'
data/README.md CHANGED
@@ -147,7 +147,7 @@ Converting spec/transpec/ast/node_spec.rb
147
147
 
148
148
  This will run the specs, convert them, and overwrite all spec files in the `spec` directory.
149
149
 
150
- After the conversion, run `rspec` again and check whether everything is green:
150
+ After the conversion, run `rspec` again and check whether everything is still green:
151
151
 
152
152
  ```bash
153
153
  $ bundle exec rspec
@@ -164,7 +164,7 @@ And you are done!
164
164
 
165
165
  ## Advanced Usage
166
166
 
167
- ### Convert only specific specs
167
+ ### Convert only specific files
168
168
 
169
169
  You can pass `transpec` arbitrary paths to convert:
170
170
 
@@ -183,15 +183,17 @@ $ transpec spec/baz_spec.rb
183
183
  ```
184
184
 
185
185
  Note that the current working directory always needs to be the project root directory,
186
- so that Transpec can copy the project in dynamic analysis.
186
+ so that Transpec can know where the root is.
187
187
 
188
188
  ### Enable/disable specific conversions
189
189
 
190
190
  You can disable specific conversions that are enabled by default with `-k/--keep` option,
191
191
  and enable conversions that are disabled by default with the `-v/--convert` option.
192
192
 
193
- ```bash
194
- $ transpec --keep its --convert example_group
193
+ If you are willing to try the latest and modern syntax, type the following:
194
+
195
+ ```
196
+ $ transpec --convert example_group,hook_scope
195
197
  ```
196
198
 
197
199
  See [`-k/--keep`](#-k--keep) and [`-v/--convert`](#-v--convert) for more details.
@@ -325,6 +327,12 @@ Note that this is not same as `--keep deprecated` since this configures `yield_r
325
327
 
326
328
  See [Supported Conversions - `any_instance` implementation blocks](#any_instance-implementation-blocks) for more details.
327
329
 
330
+ ### `-t/--no-explicit-spec-type`
331
+
332
+ Suppress adding explicit spec `:type` metadata to example groups in a project using rspec-rails.
333
+
334
+ See [Supported Conversions - Implicit spec types in rspec-rails](#implicit-spec-types-in-rspec-rails) for more details.
335
+
328
336
  ### `-p/--no-parens-matcher-arg`
329
337
 
330
338
  Suppress parenthesizing arguments of matchers when converting
data/README.md.erb CHANGED
@@ -121,7 +121,7 @@ Converting spec/transpec/ast/node_spec.rb
121
121
 
122
122
  This will run the specs, convert them, and overwrite all spec files in the `spec` directory.
123
123
 
124
- After the conversion, run `rspec` again and check whether everything is green:
124
+ After the conversion, run `rspec` again and check whether everything is still green:
125
125
 
126
126
  ```bash
127
127
  $ bundle exec rspec
@@ -138,7 +138,7 @@ And you are done!
138
138
 
139
139
  ## Advanced Usage
140
140
 
141
- ### Convert only specific specs
141
+ ### Convert only specific files
142
142
 
143
143
  You can pass `transpec` arbitrary paths to convert:
144
144
 
@@ -157,15 +157,17 @@ $ transpec spec/baz_spec.rb
157
157
  ```
158
158
 
159
159
  Note that the current working directory always needs to be the project root directory,
160
- so that Transpec can copy the project in dynamic analysis.
160
+ so that Transpec can know where the root is.
161
161
 
162
162
  ### Enable/disable specific conversions
163
163
 
164
164
  You can disable specific conversions that are enabled by default with `-k/--keep` option,
165
165
  and enable conversions that are disabled by default with the `-v/--convert` option.
166
166
 
167
- ```bash
168
- $ transpec --keep its --convert example_group
167
+ If you are willing to try the latest and modern syntax, type the following:
168
+
169
+ ```
170
+ $ transpec --convert example_group,hook_scope
169
171
  ```
170
172
 
171
173
  See [`-k/--keep`](#-k--keep) and [`-v/--convert`](#-v--convert) for more details.
@@ -313,6 +315,12 @@ Note that this is not same as `--keep deprecated` since this configures `yield_r
313
315
 
314
316
  See [Supported Conversions - `any_instance` implementation blocks](#any_instance-implementation-blocks) for more details.
315
317
 
318
+ ### `-t/--no-explicit-spec-type`
319
+
320
+ Suppress adding explicit spec `:type` metadata to example groups in a project using rspec-rails.
321
+
322
+ See [Supported Conversions - Implicit spec types in rspec-rails](#implicit-spec-types-in-rspec-rails) for more details.
323
+
316
324
  ### `-p/--no-parens-matcher-arg`
317
325
 
318
326
  Suppress parenthesizing arguments of matchers when converting
@@ -1,88 +1,15 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'parser'
3
+ require 'astrolabe/node'
4
4
 
5
5
  module Transpec
6
6
  module AST
7
- class Node < Parser::AST::Node
7
+ class Node < Astrolabe::Node
8
8
  attr_reader :metadata
9
9
 
10
10
  def initialize(type, children = [], properties = {})
11
11
  @metadata = {}
12
- @mutable_attributes = {}
13
-
14
- # ::AST::Node#initialize freezes itself.
15
12
  super
16
-
17
- each_child_node do |child_node|
18
- child_node.parent_node = self
19
- end
20
- end
21
-
22
- Parser::Meta::NODE_TYPES.each do |node_type|
23
- method_name = "#{node_type.to_s.gsub(/\W/, '')}_type?"
24
- define_method(method_name) do
25
- type == node_type
26
- end
27
- end
28
-
29
- def parent_node
30
- @mutable_attributes[:parent_node]
31
- end
32
-
33
- def parent_node=(node)
34
- @mutable_attributes[:parent_node] = node
35
- end
36
-
37
- protected :parent_node=
38
-
39
- def each_ancestor_node(&block)
40
- return to_enum(__method__) unless block_given?
41
-
42
- if parent_node
43
- yield parent_node
44
- parent_node.each_ancestor_node(&block)
45
- end
46
-
47
- self
48
- end
49
-
50
- def ancestor_nodes
51
- each_ancestor_node.to_a
52
- end
53
-
54
- def each_child_node
55
- return to_enum(__method__) unless block_given?
56
-
57
- children.each do |child|
58
- next unless child.is_a?(self.class)
59
- yield child
60
- end
61
-
62
- self
63
- end
64
-
65
- def child_nodes
66
- each_child_node.to_a
67
- end
68
-
69
- def each_descendent_node(&block)
70
- return to_enum(__method__) unless block_given?
71
-
72
- each_child_node do |child_node|
73
- yield child_node
74
- child_node.each_descendent_node(&block)
75
- end
76
- end
77
-
78
- def descendent_nodes
79
- each_descendent_node.to_a
80
- end
81
-
82
- def each_node(&block)
83
- return to_enum(__method__) unless block_given?
84
- yield self
85
- each_descendent_node(&block)
86
13
  end
87
14
  end
88
15
  end
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+
3
+ require 'fileutils'
4
+ require 'find'
5
+ require 'pathname'
6
+
7
+ module Transpec
8
+ # This module performs almost the same thing as FileUtils#cp_r, expect ignoring pseudo files
9
+ # (e.g.pipe, socket).
10
+ module DirectoryCloner
11
+ module_function
12
+
13
+ def copy_recursively(source_root, destination_root)
14
+ source_root = File.expand_path(source_root)
15
+ source_root_pathname = Pathname.new(source_root)
16
+
17
+ destination_root = File.expand_path(destination_root)
18
+ if File.directory?(destination_root)
19
+ destination_root = File.join(destination_root, File.basename(source_root))
20
+ end
21
+
22
+ Find.find(source_root) do |source_path|
23
+ relative_path = Pathname.new(source_path).relative_path_from(source_root_pathname).to_s
24
+ destination_path = File.join(destination_root, relative_path)
25
+ copy(source_path, destination_path)
26
+ end
27
+
28
+ destination_root
29
+ end
30
+
31
+ def copy(source, destination)
32
+ if File.symlink?(source)
33
+ File.symlink(File.readlink(source), destination)
34
+ elsif File.directory?(source)
35
+ FileUtils.mkdir_p(destination)
36
+ elsif File.file?(source)
37
+ FileUtils.copy_file(source, destination)
38
+ end
39
+
40
+ copy_permission(source, destination) if File.exist?(destination)
41
+ end
42
+
43
+ def copy_permission(source, destination)
44
+ source_mode = File.lstat(source).mode
45
+ begin
46
+ File.lchmod(source_mode, destination)
47
+ rescue NotImplementedError, Errno::ENOSYS
48
+ # Should not change mode of symlink's destination.
49
+ File.chmod(source_mode, destination) unless File.symlink?(destination)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -2,14 +2,12 @@
2
2
 
3
3
  require 'transpec/dynamic_analyzer/rewriter'
4
4
  require 'transpec/dynamic_analyzer/runtime_data'
5
+ require 'transpec/directory_cloner'
5
6
  require 'transpec/project'
6
7
  require 'transpec/spec_suite'
7
- require 'tmpdir'
8
- require 'find'
9
- require 'pathname'
10
- require 'fileutils'
11
- require 'shellwords'
12
8
  require 'erb'
9
+ require 'shellwords'
10
+ require 'tmpdir'
13
11
  require 'English'
14
12
 
15
13
  module Transpec
@@ -47,30 +45,7 @@ module Transpec
47
45
  put_analysis_helper
48
46
  modify_dot_rspec
49
47
  run_rspec(paths)
50
-
51
- begin
52
- File.open(RESULT_FILE) do |file|
53
- RuntimeData.load(file)
54
- end
55
- rescue
56
- raise AnalysisError
57
- end
58
- end
59
- end
60
-
61
- def copy_recursively(source_root, destination_root)
62
- source_root = File.expand_path(source_root)
63
- source_root_pathname = Pathname.new(source_root)
64
-
65
- destination_root = File.expand_path(destination_root)
66
- if File.directory?(destination_root)
67
- destination_root = File.join(destination_root, File.basename(source_root))
68
- end
69
-
70
- Find.find(source_root) do |source_path|
71
- relative_path = Pathname.new(source_path).relative_path_from(source_root_pathname).to_s
72
- destination_path = File.join(destination_root, relative_path)
73
- copy(source_path, destination_path)
48
+ load_analysis_result
74
49
  end
75
50
  end
76
51
 
@@ -82,8 +57,7 @@ module Transpec
82
57
  @in_copied_project = true
83
58
 
84
59
  Dir.mktmpdir do |tmpdir|
85
- copy_recursively(project.path, tmpdir)
86
- copied_project_path = File.join(tmpdir, project.basename)
60
+ copied_project_path = DirectoryCloner.copy_recursively(project.path, tmpdir)
87
61
  Dir.chdir(copied_project_path) do
88
62
  yield
89
63
  end
@@ -136,26 +110,12 @@ module Transpec
136
110
  File.write(filename, content)
137
111
  end
138
112
 
139
- def copy(source, destination)
140
- if File.symlink?(source)
141
- File.symlink(File.readlink(source), destination)
142
- elsif File.directory?(source)
143
- FileUtils.mkdir_p(destination)
144
- elsif File.file?(source)
145
- FileUtils.copy_file(source, destination)
146
- end
147
-
148
- copy_permission(source, destination) if File.exist?(destination)
149
- end
150
-
151
- def copy_permission(source, destination)
152
- source_mode = File.lstat(source).mode
153
- begin
154
- File.lchmod(source_mode, destination)
155
- rescue NotImplementedError, Errno::ENOSYS
156
- # Should not change mode of symlink's destination.
157
- File.chmod(source_mode, destination) unless File.symlink?(destination)
113
+ def load_analysis_result
114
+ File.open(RESULT_FILE) do |file|
115
+ RuntimeData.load(file)
158
116
  end
117
+ rescue
118
+ raise AnalysisError
159
119
  end
160
120
 
161
121
  class AnalysisError < StandardError; end
@@ -98,13 +98,22 @@ module Transpec
98
98
  new(*args).build
99
99
  end
100
100
 
101
+ def self.param_names(*names)
102
+ names.each_with_index do |name, index|
103
+ define_method(name) do
104
+ @initializer_params[index]
105
+ end
106
+ end
107
+ end
108
+
101
109
  def build
102
110
  Record.new(old_syntax, new_syntax, { type: type, annotation: annotation })
103
111
  end
104
112
 
105
113
  private
106
114
 
107
- def initialize(*)
115
+ def initialize(*params)
116
+ @initializer_params = params
108
117
  end
109
118
 
110
119
  def old_syntax
@@ -3,8 +3,6 @@
3
3
  # Aliases by Capybara:
4
4
  # https://github.com/jnicklas/capybara/blob/2.2.0/lib/capybara/rspec/features.rb
5
5
 
6
- # rubocop:disable LineLength
7
-
8
6
  module Transpec
9
7
  module RSpecDSL
10
8
  # https://github.com/rspec/rspec-core/blob/77cc21e/lib/rspec/core/example_group.rb#L239-L265
@@ -68,7 +68,7 @@ module Transpec
68
68
  def valid_ancestor_nodes
69
69
  valid_nodes = []
70
70
 
71
- self_and_ancestor_nodes = [node] + node.ancestor_nodes
71
+ self_and_ancestor_nodes = [node] + node.each_ancestor.to_a
72
72
 
73
73
  self_and_ancestor_nodes.each_cons(2) do |child, parent|
74
74
  valid_nodes << parent unless belong_to_direct_outer_scope?(child)
@@ -78,8 +78,8 @@ module Transpec
78
78
  end
79
79
 
80
80
  def belong_to_direct_outer_scope?(node)
81
- return false unless TWISTED_SCOPE_TYPES.include?(node.parent_node.type)
82
- scope_node = node.parent_node
81
+ return false unless TWISTED_SCOPE_TYPES.include?(node.parent.type)
82
+ scope_node = node.parent
83
83
  return true if node.equal?(scope_node.children[0])
84
84
  scope_node.class_type? && node.equal?(scope_node.children[1])
85
85
  end
@@ -34,9 +34,8 @@ module Transpec
34
34
  def block_node
35
35
  return @block_node if instance_variable_defined?(:@block_node)
36
36
 
37
- @block_node ||= node.each_ancestor_node.find do |ancestor_node|
38
- next false unless ancestor_node.block_type?
39
- method_name = method_name_of_block_node(ancestor_node)
37
+ @block_node = node.each_ancestor(:block).find do |block_node|
38
+ method_name = method_name_of_block_node(block_node)
40
39
  METHODS_YIELD_EXAMPLE.include?(method_name)
41
40
  end
42
41
  end
@@ -72,11 +71,7 @@ module Transpec
72
71
  class RecordBuilder < Transpec::RecordBuilder
73
72
  include RSpecDSL
74
73
 
75
- attr_reader :current_example
76
-
77
- def initialize(current_example)
78
- @current_example = current_example
79
- end
74
+ param_names :current_example
80
75
 
81
76
  def old_syntax
82
77
  if current_example.block_node
@@ -40,7 +40,7 @@ module Transpec
40
40
  metadata_key_nodes.each do |node|
41
41
  next unless pending_symbol?(node)
42
42
  replace(symbol_range_without_colon(node), 'skip')
43
- if node.parent_node.pair_type?
43
+ if node.parent.pair_type?
44
44
  add_record("it 'is an example', :pending => value { }",
45
45
  "it 'is an example', :skip => value { }")
46
46
  else
@@ -57,7 +57,7 @@ module Transpec
57
57
  "type: #{type.inspect}"
58
58
  end
59
59
 
60
- insert_after(arg_node.loc.expression, code)
60
+ insert_after(metadata_insertion_point, code)
61
61
 
62
62
  add_record(ExplicitTypeMetadataRecordBuilder.build(self))
63
63
  end
@@ -96,12 +96,20 @@ module Transpec
96
96
  end
97
97
  end
98
98
 
99
- class NonMonkeyPatchRecordBuilder < RecordBuilder
100
- attr_reader :example_group
99
+ def metadata_insertion_point
100
+ hash_metadata_node_index = arg_nodes.find_index(&:hash_type?)
101
101
 
102
- def initialize(example_group)
103
- @example_group = example_group
104
- end
102
+ last_non_hash_arg_node = if hash_metadata_node_index
103
+ arg_nodes[hash_metadata_node_index - 1]
104
+ else
105
+ arg_nodes.last
106
+ end
107
+
108
+ last_non_hash_arg_node.loc.expression.end
109
+ end
110
+
111
+ class NonMonkeyPatchRecordBuilder < RecordBuilder
112
+ param_names :example_group
105
113
 
106
114
  def old_syntax
107
115
  base_syntax
@@ -117,11 +125,7 @@ module Transpec
117
125
  end
118
126
 
119
127
  class ExplicitTypeMetadataRecordBuilder < RecordBuilder
120
- attr_reader :example_group
121
-
122
- def initialize(example_group)
123
- @example_group = example_group
124
- end
128
+ param_names :example_group
125
129
 
126
130
  def old_syntax
127
131
  "describe 'some #{spec_type}' { }"
@@ -47,9 +47,7 @@ module Transpec
47
47
  # `expect(owner).to have(n).things` invokes private owner#things with Object#__send__
48
48
  # if the owner does not respond to any of #size, #count and #length.
49
49
  #
50
- # rubocop:disable LineLength
51
50
  # https://github.com/rspec/rspec-expectations/blob/v2.14.3/lib/rspec/matchers/built_in/have.rb#L48-L58
52
- # rubocop:enable LineLength
53
51
  @collection_accessor_inspection_code ||= <<-END.gsub(/^\s+\|/, '').chomp
54
52
  |begin
55
53
  | exact_name = #{items_name.inspect}
@@ -6,11 +6,7 @@ module Transpec
6
6
  class Syntax
7
7
  class Have
8
8
  class RecordBuilder < Transpec::RecordBuilder
9
- attr_reader :have
10
-
11
- def initialize(have)
12
- @have = have
13
- end
9
+ param_names :have
14
10
 
15
11
  def annotation
16
12
  return @annotation if instance_variable_defined?(:@annotation)
@@ -50,7 +50,7 @@ module Transpec
50
50
  alias_method :attribute_node, :arg_node
51
51
 
52
52
  def block_node
53
- node.parent_node
53
+ node.parent
54
54
  end
55
55
 
56
56
  def description?
@@ -182,11 +182,7 @@ module Transpec
182
182
  Attribute = Struct.new(:selector, :description)
183
183
 
184
184
  class RecordBuilder < Transpec::RecordBuilder
185
- attr_reader :its
186
-
187
- def initialize(its)
188
- @its = its
189
- end
185
+ param_names :its
190
186
 
191
187
  def old_syntax
192
188
  if its.attribute_expression.brackets?
@@ -11,13 +11,11 @@ module Transpec
11
11
  class MethodStub < Syntax
12
12
  include Mixin::MonkeyPatchAnyInstance, Mixin::MessagingHost, Util
13
13
 
14
- # rubocop:disable LineLength
15
14
  CLASSES_DEFINING_OWN_STUB_METHOD = [
16
15
  'Typhoeus', # https://github.com/typhoeus/typhoeus/blob/6a59c62/lib/typhoeus.rb#L66-L85
17
16
  'Excon', # https://github.com/geemus/excon/blob/6af4f9c/lib/excon.rb#L143-L178
18
17
  'Factory' # https://github.com/thoughtbot/factory_girl/blob/v3.6.2/lib/factory_girl/syntax/vintage.rb#L112
19
18
  ]
20
- # rubocop:enable LineLength
21
19
 
22
20
  define_dynamic_analysis do |rewriter|
23
21
  register_syntax_availability_analysis_request(
@@ -170,12 +168,7 @@ module Transpec
170
168
  end
171
169
 
172
170
  class AllowRecordBuilder < RecordBuilder
173
- attr_reader :method_stub, :conversion_type
174
-
175
- def initialize(method_stub, conversion_type)
176
- @method_stub = method_stub
177
- @conversion_type = conversion_type
178
- end
171
+ param_names :method_stub, :conversion_type
179
172
 
180
173
  def old_syntax
181
174
  syntax = method_stub.any_instance? ? 'Klass.any_instance' : 'obj'
@@ -208,11 +201,7 @@ module Transpec
208
201
  end
209
202
 
210
203
  class DeprecatedMethodRecordBuilder < RecordBuilder
211
- attr_reader :method_stub
212
-
213
- def initialize(method_stub)
214
- @method_stub = method_stub
215
- end
204
+ param_names :method_stub
216
205
 
217
206
  def old_syntax
218
207
  syntax = method_stub.any_instance? ? 'Klass.any_instance' : 'obj'
@@ -227,16 +216,12 @@ module Transpec
227
216
  end
228
217
 
229
218
  class NoMessageAllowanceRecordBuilder < RecordBuilder
230
- attr_reader :method_stub
231
-
232
- def initialize(method_stub)
233
- @method_stub = method_stub
234
- end
219
+ param_names :method_stub
235
220
 
236
221
  def old_syntax
237
222
  syntax = base_syntax
238
- syntax << '.any_number_of_times' if @method_stub.any_number_of_times?
239
- syntax << '.at_least(0)' if @method_stub.at_least_zero?
223
+ syntax << '.any_number_of_times' if method_stub.any_number_of_times?
224
+ syntax << '.at_least(0)' if method_stub.at_least_zero?
240
225
  syntax
241
226
  end
242
227
 
@@ -245,7 +230,7 @@ module Transpec
245
230
  end
246
231
 
247
232
  def base_syntax
248
- "obj.#{@method_stub.method_name}(:message)"
233
+ "obj.#{method_stub.method_name}(:message)"
249
234
  end
250
235
  end
251
236
  end
@@ -37,11 +37,7 @@ module Transpec
37
37
  end
38
38
 
39
39
  class RecordBuilder < Transpec::RecordBuilder
40
- attr_reader :host
41
-
42
- def initialize(host)
43
- @host = host
44
- end
40
+ param_names :host
45
41
 
46
42
  def old_syntax
47
43
  "#{base_syntax} { |arg| }"
@@ -43,7 +43,7 @@ module Transpec
43
43
  return nil unless parent_node
44
44
 
45
45
  if parent_node.block_type? && parent_node.children.first.equal?(node)
46
- parent_node.parent_node
46
+ parent_node.parent
47
47
  elsif parent_node.send_type? && parent_node.children.first.equal?(node)
48
48
  parent_node
49
49
  else
@@ -11,7 +11,16 @@ module Transpec
11
11
  include Send
12
12
 
13
13
  def metadata_nodes
14
- arg_nodes[1..-1] || []
14
+ return arg_nodes if arg_nodes.empty?
15
+
16
+ # The first argument must be always description.
17
+ non_description_arg_nodes = arg_nodes.drop(1)
18
+
19
+ non_description_arg_nodes.drop_while do |node|
20
+ # Possibly there still may be descriptions after the first arg.
21
+ # describe 'something', '#some_method', :foo, bar: true { }
22
+ ![:hash, :sym].include?(node.type)
23
+ end
15
24
  end
16
25
 
17
26
  def metadata_key_nodes