transpec 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b8de9ebab18fff6380696a3a783ccf4ce9ed8af
4
- data.tar.gz: e193341f8e9614397330090af1eff772a5efe427
3
+ metadata.gz: cb53fd56a9663b6ac60c9fcb539aa9f08ce4ef48
4
+ data.tar.gz: 483a8e18c082daa89c45a80a67397c5fab6dc7df
5
5
  SHA512:
6
- metadata.gz: 0a77f0a729eb8d00145ff1b0c2af16d4ddb86e4187391077ff63a96be47ffebf7d9c641c43ef9c99250f99a89808c1e039d031b6bf109cf6e6bbaea2411b47e6
7
- data.tar.gz: a98eb793b1d027164f716938ddec92f5ed2f70a19363fbe0a66d537d872f2e2f4d405f0dd246bada22a965366fecbb4943ffaf76b5ff04f175f7c8a8e31a13a0
6
+ metadata.gz: 29bdf20766286e22243e0d615b2cb934d86272ad6fec7b2a67d3e53fdb6c19d19f732c95ad3ff7fd6f7bf6732b9665c99d7f9e79a490af3ee4c2ba6a2812afe2
7
+ data.tar.gz: eeee1c1f55c9dfa1893be85c04a576f62286a35a60ce0359acbc91c1bf530a334cf6b47345525aa70ce2ec2730f05b20eb29f0159e3ecf700a22b0296a2dd014
data/.rubocop.yml CHANGED
@@ -58,4 +58,4 @@ BracesAroundHashParameters:
58
58
 
59
59
  # TODO: Shorten to 100.
60
60
  ClassLength:
61
- Max: 152
61
+ Max: 154
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v1.5.0
6
+
7
+ * Mention the project's RSpec version in the auto-generated commit message
8
+ * Deprecate `-m/--generate-commit-message` option (A commit message will always be generated)
9
+ * Display actual `Proc` constructor names in the summary of expectations on block
10
+
5
11
  ## v1.4.1
6
12
 
7
13
  * Support Ruby 2.1 runtime by falling back to Ruby 2.0 parser
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard :rspec, all_after_pass: true, all_on_start: true, keep_failed: true, cmd: 'bundle exec rspec' do
4
+ guard :rspec, all_after_pass: true, all_on_start: true, cmd: 'bundle exec rspec' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -113,15 +113,15 @@ Usually you don't need to add `transpec` to your `*.gemspec` or `Gemfile` since
113
113
 
114
114
  Before converting your specs:
115
115
 
116
- * Make sure your project has `rspec` gem dependency `2.14` or later. If not, change your `*.gemspec` or `Gemfile` to do so.
116
+ * Make sure your project has `rspec` gem dependency **2.14** or later. If not, change your `*.gemspec` or `Gemfile` to do so.
117
117
  * Run `rspec` and check if all the specs pass.
118
118
  * Ensure the Git repository is clean. (You don't want to mix up your changes and Transpec's changes, right?)
119
119
 
120
- Then, run `transpec` (using `-m/--generate-commit-message` is recommended) in the project root directory:
120
+ Then, run `transpec` in the project root directory:
121
121
 
122
122
  ```bash
123
123
  $ cd some-project
124
- $ transpec -m
124
+ $ transpec
125
125
  Copying the project for dynamic analysis...
126
126
  Running dynamic analysis with command "bundle exec rspec"...
127
127
  ...............................................................................
@@ -145,7 +145,7 @@ After the conversion, run `rspec` again and check whether everything is green:
145
145
  $ bundle exec rspec
146
146
  ```
147
147
 
148
- If it's green, commit the changes with auto-generated message:
148
+ If it's green, commit the changes with an auto-generated message that describes the conversion summary:
149
149
 
150
150
  ```bash
151
151
  $ git commit -aeF .git/COMMIT_EDITMSG
@@ -181,7 +181,7 @@ Skip dynamic analysis and convert with only static analysis. Note that specifyin
181
181
 
182
182
  ### `-c/--rspec-command`
183
183
 
184
- Specify a command to run RSpec that is used for dynamic analysis.
184
+ Specify a command to run your specs that is used for dynamic analysis.
185
185
 
186
186
  Transpec needs to run your specs in a copied project directory for dynamic analysis.
187
187
  If your project requires some special setups or commands to run specs, use this option.
@@ -191,17 +191,6 @@ If your project requires some special setups or commands to run specs, use this
191
191
  $ transpec --rspec-command "./special_setup.sh && bundle exec rspec"
192
192
  ```
193
193
 
194
- ### `-m/--generate-commit-message`
195
-
196
- Generate a commit message that describes conversion summary.
197
- Currently only Git is supported.
198
-
199
- When you commit, you need to run the following command to use the generated message:
200
-
201
- ```bash
202
- $ git commit -eF .git/COMMIT_EDITMSG
203
- ```
204
-
205
194
  ### `-k/--keep`
206
195
 
207
196
  Keep specific syntaxes by disabling conversions.
@@ -218,7 +207,7 @@ Type | Target Syntax | Converted Syntax
218
207
  `oneliner` | `it { should ... }` | `it { is_expected.to ... }`
219
208
  `should_receive` | `obj.should_receive` | `expect(obj).to receive`
220
209
  `stub` | `obj.stub` | `allow(obj).to receive`
221
- `have_items` | `expect(obj).to have(x).items` | `expect(obj.size).to eq(x)`
210
+ `have_items` | `expect(obj).to have(n).items` | `expect(obj.size).to eq(n)`
222
211
  `its` | `its(:attr) { }` | `describe { subject { }; it { } }`
223
212
  `deprecated` | `obj.stub!`, `mock('foo')`, etc. | `obj.stub`, `double('foo')`
224
213
 
@@ -620,7 +609,7 @@ allow(obj).to receive(:bar).and_return(2)
620
609
  allow(obj).to receive_messages(:foo => 1, :bar => 2)
621
610
 
622
611
  # Conversion from `stub_chain` to `receive_message_chain` is available
623
- # only if the target project's rspec gem dependency is 2.99.0.beta2 or later
612
+ # only if the target project's rspec gem dependency is 3.0.0.beta2 or later
624
613
  allow(obj).to receive_message_chain(:foo, :bar, :baz)
625
614
 
626
615
  allow_any_instance_of(Klass).to receive(:foo)
@@ -648,6 +637,7 @@ Otherwise `obj.stub(:foo => 1, :bar => 2)` will be converted to two `allow(obj).
648
637
  * See also:
649
638
  * [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
650
639
  * [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
640
+ * [Bring back stub_chain (receive_message_chain) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/464)
651
641
 
652
642
  ### Deprecated method stub aliases
653
643
 
data/README.md.erb CHANGED
@@ -86,15 +86,15 @@ Usually you don't need to add `transpec` to your `*.gemspec` or `Gemfile` since
86
86
 
87
87
  Before converting your specs:
88
88
 
89
- * Make sure your project has `rspec` gem dependency `<%= Transpec.required_rspec_version %>` or later. If not, change your `*.gemspec` or `Gemfile` to do so.
89
+ * Make sure your project has `rspec` gem dependency **<%= Transpec.required_rspec_version %>** or later. If not, change your `*.gemspec` or `Gemfile` to do so.
90
90
  * Run `rspec` and check if all the specs pass.
91
91
  * Ensure the Git repository is clean. (You don't want to mix up your changes and Transpec's changes, right?)
92
92
 
93
- Then, run `transpec` (using `-m/--generate-commit-message` is recommended) in the project root directory:
93
+ Then, run `transpec` in the project root directory:
94
94
 
95
95
  ```bash
96
96
  $ cd some-project
97
- $ transpec -m
97
+ $ transpec
98
98
  Copying the project for dynamic analysis...
99
99
  Running dynamic analysis with command "bundle exec rspec"...
100
100
  ...............................................................................
@@ -118,7 +118,7 @@ After the conversion, run `rspec` again and check whether everything is green:
118
118
  $ bundle exec rspec
119
119
  ```
120
120
 
121
- If it's green, commit the changes with auto-generated message:
121
+ If it's green, commit the changes with an auto-generated message that describes the conversion summary:
122
122
 
123
123
  ```bash
124
124
  $ git commit -aeF .git/COMMIT_EDITMSG
@@ -154,7 +154,7 @@ Skip dynamic analysis and convert with only static analysis. Note that specifyin
154
154
 
155
155
  ### `-c/--rspec-command`
156
156
 
157
- Specify a command to run RSpec that is used for dynamic analysis.
157
+ Specify a command to run your specs that is used for dynamic analysis.
158
158
 
159
159
  Transpec needs to run your specs in a copied project directory for dynamic analysis.
160
160
  If your project requires some special setups or commands to run specs, use this option.
@@ -164,17 +164,6 @@ If your project requires some special setups or commands to run specs, use this
164
164
  $ transpec --rspec-command "./special_setup.sh && bundle exec rspec"
165
165
  ```
166
166
 
167
- ### `-m/--generate-commit-message`
168
-
169
- Generate a commit message that describes conversion summary.
170
- Currently only Git is supported.
171
-
172
- When you commit, you need to run the following command to use the generated message:
173
-
174
- ```bash
175
- $ git commit -eF .git/COMMIT_EDITMSG
176
- ```
177
-
178
167
  ### `-k/--keep`
179
168
 
180
169
  Keep specific syntaxes by disabling conversions.
@@ -193,7 +182,7 @@ conversion_type_table = <<END
193
182
  `oneliner` | `it { should ... }` | `it { is_expected.to ... }`
194
183
  `should_receive` | `obj.should_receive` | `expect(obj).to receive`
195
184
  `stub` | `obj.stub` | `allow(obj).to receive`
196
- `have_items` | `expect(obj).to have(x).items` | `expect(obj.size).to eq(x)`
185
+ `have_items` | `expect(obj).to have(n).items` | `expect(obj.size).to eq(n)`
197
186
  `its` | `its(:attr) { }` | `describe { subject { }; it { } }`
198
187
  `deprecated` | `obj.stub!`, `mock('foo')`, etc. | `obj.stub`, `double('foo')`
199
188
  END
@@ -355,7 +344,7 @@ expect(obj).to_not matcher # with `--negative-form to_not`
355
344
 
356
345
  ### One-liner expectations
357
346
 
358
- **This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta2` or later.**
347
+ **This conversion is available only if your project has `rspec` gem dependency `<%= Transpec::RSpecVersion.one_liner_is_expected_available_version %>` or later.**
359
348
 
360
349
  ```ruby
361
350
  # Targets
@@ -402,7 +391,7 @@ This conversion is combined with the conversion of [standard expectations](#stan
402
391
 
403
392
  ### Boolean matchers
404
393
 
405
- **This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta1` or later.**
394
+ **This conversion is available only if your project has `rspec` gem dependency `<%= Transpec::RSpecVersion.be_truthy_available_version %>` or later.**
406
395
 
407
396
  ```ruby
408
397
  # Targets
@@ -608,15 +597,15 @@ Klass.any_instance.stub(:foo)
608
597
  # Converted
609
598
  allow(obj).to receive(:foo)
610
599
 
611
- # If the target project's rspec gem dependency is prior to 3.0.0.beta1
600
+ # If the target project's rspec gem dependency is prior to <%= Transpec::RSpecVersion.receive_messages_available_version %>
612
601
  allow(obj).to receive(:foo).and_return(1)
613
602
  allow(obj).to receive(:bar).and_return(2)
614
603
 
615
- # If the target project's rspec gem dependency is 3.0.0.beta1 or later
604
+ # If the target project's rspec gem dependency is <%= Transpec::RSpecVersion.receive_messages_available_version %> or later
616
605
  allow(obj).to receive_messages(:foo => 1, :bar => 2)
617
606
 
618
607
  # Conversion from `stub_chain` to `receive_message_chain` is available
619
- # only if the target project's rspec gem dependency is 2.99.0.beta2 or later
608
+ # only if the target project's rspec gem dependency is <%= Transpec::RSpecVersion.receive_message_chain_available_version %> or later
620
609
  allow(obj).to receive_message_chain(:foo, :bar, :baz)
621
610
 
622
611
  allow_any_instance_of(Klass).to receive(:foo)
@@ -644,6 +633,7 @@ Otherwise `obj.stub(:foo => 1, :bar => 2)` will be converted to two `allow(obj).
644
633
  * See also:
645
634
  * [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
646
635
  * [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
636
+ * [Bring back stub_chain (receive_message_chain) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/464)
647
637
 
648
638
  ### Deprecated method stub aliases
649
639
 
@@ -727,7 +717,7 @@ If you choose so, disable this conversion by either:
727
717
 
728
718
  ### Current example object
729
719
 
730
- **This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta1` or later.**
720
+ **This conversion is available only if your project has `rspec` gem dependency `<%= Transpec::RSpecVersion.yielded_example_available_version %>` or later.**
731
721
 
732
722
  ```ruby
733
723
  # Targets
@@ -751,7 +741,7 @@ END
751
741
 
752
742
  # Converted
753
743
  <%=
754
- rspec_version = Transpec::RSpecVersion.new('2.99')
744
+ rspec_version = Transpec::RSpecVersion.yielded_example_available_version
755
745
  Transpec::Converter.new(nil, rspec_version).convert(example_target)
756
746
  -%>
757
747
  ```
data/lib/transpec/cli.rb CHANGED
@@ -36,7 +36,7 @@ module Transpec
36
36
  process(paths)
37
37
 
38
38
  display_summary
39
- generate_commit_message if @configuration.generate_commit_message?
39
+ generate_commit_message
40
40
  display_final_guide
41
41
 
42
42
  true
@@ -105,13 +105,15 @@ module Transpec
105
105
 
106
106
  def generate_commit_message
107
107
  return if @report.records.empty?
108
+ return unless Git.command_available? && Git.inside_of_repository?
108
109
 
109
- commit_message = CommitMessage.new(@report, ARGV)
110
+ commit_message = CommitMessage.new(@report, @project.rspec_version, ARGV)
110
111
  Git.write_commit_message(commit_message.to_s)
111
112
 
112
113
  puts
113
- puts 'A commit message was generated to .git/COMMIT_EDITMSG.'.color(:cyan)
114
- puts 'Use the following command for the next commit:'.color(:cyan)
114
+ puts 'A commit message that describes the conversion summary was generated to'.color(:cyan)
115
+ puts '.git/COMMIT_EDITMSG. To use the message, type the following command for'.color(:cyan)
116
+ puts 'the next commit:'.color(:cyan)
115
117
  puts ' git commit -eF .git/COMMIT_EDITMSG'
116
118
  end
117
119
 
@@ -4,8 +4,9 @@ require 'transpec/version'
4
4
 
5
5
  module Transpec
6
6
  class CommitMessage
7
- def initialize(report, cli_args = [])
7
+ def initialize(report, rspec_version, cli_args = [])
8
8
  @report = report
9
+ @rspec_version = rspec_version
9
10
  @cli_args = cli_args
10
11
  end
11
12
 
@@ -13,7 +14,7 @@ module Transpec
13
14
  conversion_summary = @report.summary(bullet: '*', separate_by_blank_line: true)
14
15
 
15
16
  <<-END.gsub(/^\s+\|/, '').chomp
16
- |Convert specs to the latest RSpec syntax with Transpec
17
+ |Convert specs to RSpec #{@rspec_version} syntax with Transpec
17
18
  |
18
19
  |This conversion is done by Transpec #{Transpec::Version} with the following command:
19
20
  | transpec #{@cli_args.join(' ')}
@@ -16,8 +16,7 @@ module Transpec
16
16
  [:convert_deprecated_method, true],
17
17
  [:parenthesize_matcher_arg, true],
18
18
  [:forced, false],
19
- [:skip_dynamic_analysis, false],
20
- [:generate_commit_message, false]
19
+ [:skip_dynamic_analysis, false]
21
20
  ].freeze
22
21
 
23
22
  PREDICATES.each do |predicate, _|
@@ -32,7 +32,7 @@ module Transpec
32
32
  end
33
33
 
34
34
  def parse(args)
35
- args = args.dup
35
+ args = exclude_deprecated_options(args)
36
36
  @parser.parse!(args)
37
37
  args
38
38
  end
@@ -59,14 +59,6 @@ module Transpec
59
59
  @configuration.rspec_command = command
60
60
  end
61
61
 
62
- define_option('-m', '--generate-commit-message') do
63
- unless Git.inside_of_repository?
64
- fail '-m/--generate-commit-message option is specified but not in a Git repository'
65
- end
66
-
67
- @configuration.generate_commit_message = true
68
- end
69
-
70
62
  define_option('-k', '--keep TYPE[,TYPE...]') do |types|
71
63
  types.split(',').each do |type|
72
64
  config_attr = CONFIG_ATTRS_FOR_KEEP_TYPES[type.to_sym]
@@ -128,14 +120,10 @@ module Transpec
128
120
  'option decreases the conversion accuracy.'
129
121
  ],
130
122
  '-c' => [
131
- 'Specify command to run RSpec that is used for',
132
- 'dynamic analysis.',
123
+ 'Specify a command to run your specs that is',
124
+ 'used for dynamic analysis.',
133
125
  'Default: "bundle exec rspec"'
134
126
  ],
135
- '-m' => [
136
- 'Generate commit message that describes',
137
- 'conversion summary. Only Git is supported.'
138
- ],
139
127
  '-k' => [
140
128
  'Keep specific syntaxes by disabling',
141
129
  'conversions.',
@@ -144,13 +132,13 @@ module Transpec
144
132
  " #{'oneliner'.bright} (from #{'should'.underline} to #{'is_expected.to'.underline})",
145
133
  " #{'should_receive'.bright} (to #{'expect(obj).to receive'.underline})",
146
134
  " #{'stub'.bright} (to #{'allow(obj).to receive'.underline})",
147
- " #{'have_items'.bright} (to #{'expect(obj.size).to eq(x)'.underline})",
135
+ " #{'have_items'.bright} (to #{'expect(obj.size).to eq(n)'.underline})",
148
136
  " #{'its'.bright} (to #{'describe { subject { }; it { } }'.underline})",
149
137
  " #{'deprecated'.bright} (e.g. from #{'mock'.underline} to #{'double'.underline})",
150
138
  'These are all converted by default.'
151
139
  ],
152
140
  '-n' => [
153
- "Specify negative form of #{'to'.underline} that is used in",
141
+ "Specify a negative form of #{'to'.underline} that is used in",
154
142
  "the #{'expect(...).to'.underline} syntax.",
155
143
  "Either #{'not_to'.bright} or #{'to_not'.bright}.",
156
144
  "Default: #{'not_to'.bright}"
@@ -186,5 +174,18 @@ module Transpec
186
174
  }
187
175
  end
188
176
  # rubocop:enable MethodLength, AlignHash
177
+
178
+ def exclude_deprecated_options(args)
179
+ args.reject do |arg|
180
+ case arg
181
+ when '-m', '--generate-commit-message'
182
+ warn 'DEPRECATION: -m/--generate-commit-message option is deprecated. ' +
183
+ 'A commit message will always be generated.'
184
+ true
185
+ else
186
+ false
187
+ end
188
+ end
189
+ end
189
190
  end
190
191
  end
@@ -8,20 +8,20 @@ module Transpec
8
8
  class RSpecVersion
9
9
  include Comparable
10
10
 
11
- # http://www.ruby-doc.org/stdlib-2.0.0/libdoc/rubygems/rdoc/Gem/Version.html
12
- #
13
- # If any part contains letters (currently only a-z are supported) then that version is
14
- # considered prerelease.
15
- # Prerelease parts are sorted alphabetically using the normal Ruby string sorting rules.
16
- # If a prerelease part contains both letters and numbers, it will be broken into multiple parts
17
- # to provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is greater than 1.0.a9).
18
- GEM_VERSION_2_99_0_BETA1 = Gem::Version.new('2.99.0.beta1')
19
- GEM_VERSION_2_99_0_BETA2 = Gem::Version.new('2.99.0.beta2')
20
- GEM_VERSION_3_0_0_BETA1 = Gem::Version.new('3.0.0.beta1')
21
- GEM_VERSION_3_0_0_BETA2 = Gem::Version.new('3.0.0.beta2')
22
-
23
11
  attr_reader :gem_version
24
12
 
13
+ def self.define_feature_availability(feature, version_string)
14
+ available_version = new(version_string)
15
+
16
+ define_singleton_method("#{feature}_available_version") do
17
+ available_version
18
+ end
19
+
20
+ define_method("#{feature}_available?") do
21
+ self >= available_version
22
+ end
23
+ end
24
+
25
25
  def initialize(version)
26
26
  @gem_version = if version.is_a?(Gem::Version)
27
27
  version
@@ -30,26 +30,6 @@ module Transpec
30
30
  end
31
31
  end
32
32
 
33
- def be_truthy_available?
34
- @gem_version >= GEM_VERSION_2_99_0_BETA1
35
- end
36
-
37
- def yielded_example_available?
38
- @gem_version >= GEM_VERSION_2_99_0_BETA1
39
- end
40
-
41
- def one_liner_is_expected_available?
42
- @gem_version >= GEM_VERSION_2_99_0_BETA2
43
- end
44
-
45
- def receive_messages_available?
46
- @gem_version >= GEM_VERSION_3_0_0_BETA1
47
- end
48
-
49
- def receive_message_chain_available?
50
- @gem_version >= GEM_VERSION_3_0_0_BETA2
51
- end
52
-
53
33
  def <=>(other)
54
34
  @gem_version <=> other.gem_version
55
35
  end
@@ -57,5 +37,11 @@ module Transpec
57
37
  def to_s
58
38
  @gem_version.to_s
59
39
  end
40
+
41
+ define_feature_availability :be_truthy, '2.99.0.beta1'
42
+ define_feature_availability :yielded_example, '2.99.0.beta1'
43
+ define_feature_availability :one_liner_is_expected, '2.99.0.beta2'
44
+ define_feature_availability :receive_messages, '3.0.0.beta1'
45
+ define_feature_availability :receive_message_chain, '3.0.0.beta2'
60
46
  end
61
47
  end
@@ -2,17 +2,16 @@
2
2
 
3
3
  require 'transpec/syntax'
4
4
  require 'transpec/util'
5
+ require 'ast'
5
6
 
6
7
  module Transpec
7
8
  class Syntax
8
9
  class RSpecConfigure < Syntax
9
- extend Util
10
-
11
10
  def self.target_node?(node, runtime_data = nil)
12
11
  return false unless node && node.type == :block
13
12
  send_node = node.children.first
14
13
  receiver_node, method_name, *_ = *send_node
15
- const_name(receiver_node) == 'RSpec' && method_name == :configure
14
+ Util.const_name(receiver_node) == 'RSpec' && method_name == :configure
16
15
  end
17
16
 
18
17
  def self.add_framework_configuration(type, config_method_name)
@@ -46,7 +46,7 @@ module Transpec
46
46
  end
47
47
 
48
48
  if proc_literal?(subject_node)
49
- replace_proc_selector_with_expect!
49
+ replace(range_of_subject_method_taking_block, 'expect')
50
50
  else
51
51
  wrap_subject_in_expect!
52
52
  end
@@ -61,15 +61,14 @@ module Transpec
61
61
 
62
62
  private
63
63
 
64
- def replace_proc_selector_with_expect!
64
+ def range_of_subject_method_taking_block
65
65
  send_node = subject_node.children.first
66
- range_of_subject_method_taking_block = send_node.loc.expression
67
- replace(range_of_subject_method_taking_block, 'expect')
66
+ send_node.loc.expression
68
67
  end
69
68
 
70
69
  def register_record(negative_form_of_to)
71
70
  if proc_literal?(subject_node)
72
- original_syntax = 'lambda { }.should'
71
+ original_syntax = "#{range_of_subject_method_taking_block.source} { }.should"
73
72
  converted_syntax = 'expect { }.'
74
73
  else
75
74
  original_syntax = 'obj.should'
@@ -10,11 +10,8 @@ require 'transpec/syntax/mixin/any_instance'
10
10
  module Transpec
11
11
  class Syntax
12
12
  class ShouldReceive < Syntax
13
- include Mixin::Send
14
- include Mixin::MonkeyPatch
15
- include Mixin::Expectizable
16
- include Mixin::AllowNoMessage
17
- include Mixin::AnyInstance
13
+ include Mixin::Send, Mixin::MonkeyPatch, Mixin::Expectizable, Mixin::AllowNoMessage,
14
+ Mixin::AnyInstance
18
15
 
19
16
  alias_method :useless_expectation?, :allow_no_message?
20
17
 
@@ -4,8 +4,8 @@ module Transpec
4
4
  # http://semver.org/
5
5
  module Version
6
6
  MAJOR = 1
7
- MINOR = 4
8
- PATCH = 1
7
+ MINOR = 5
8
+ PATCH = 0
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -63,17 +63,32 @@ module Transpec
63
63
  end
64
64
  end
65
65
 
66
+ shared_examples 'generates commit message' do
67
+ it 'generates commit message to .git/COMMIT_EDITMSG' do
68
+ cli.run(args)
69
+ File.read('.git/COMMIT_EDITMSG').should start_with('Convert specs')
70
+ end
71
+ end
72
+
73
+ shared_examples 'does not generate commit message' do
74
+ it 'does not generate commit message' do
75
+ cli.run(args)
76
+ File.exist?('.git/COMMIT_EDITMSG').should be_false
77
+ end
78
+ end
79
+
66
80
  context 'when git is available' do
67
81
  before { Git.stub(:command_available?).and_return(true) }
68
82
 
69
83
  context 'and inside of a repository' do
70
- before { Git.stub(:inside_of_repository?).and_return(true) }
84
+ include_context 'inside of git repository'
71
85
 
72
86
  context 'and the repository is not clean' do
73
87
  before { Git.stub(:clean?).and_return(false) }
74
88
 
75
89
  context 'and --force option is not specified' do
76
90
  include_examples 'aborts processing'
91
+ include_examples 'does not generate commit message'
77
92
 
78
93
  it 'warns to the user' do
79
94
  cli.should_receive(:warn) do |arg|
@@ -85,32 +100,35 @@ module Transpec
85
100
  end
86
101
 
87
102
  context 'and --force option is specified' do
88
- before do
89
- args << '--force'
90
- # Silence "fatal: Not a git repository (or any of the parent directories): .git"
91
- # from Bundler.
92
- `git init`
93
- end
94
-
103
+ before { args << '--force' }
95
104
  include_examples 'rewrites files'
105
+ include_examples 'generates commit message'
96
106
  end
97
107
  end
98
108
 
99
109
  context 'and the repository is clean' do
100
110
  before { Git.stub(:clean?).and_return(true) }
111
+
101
112
  include_examples 'rewrites files'
113
+ include_examples 'generates commit message'
114
+
115
+ context 'and no conversion is done' do
116
+ let(:file_content) { '' }
117
+ include_examples 'does not generate commit message'
118
+ end
102
119
  end
103
120
  end
104
121
 
105
122
  context 'and not inside of a repository' do
106
- before { Git.stub(:inside_of_repository?).and_return(false) }
107
123
  include_examples 'rewrites files'
124
+ include_examples 'does not generate commit message'
108
125
  end
109
126
  end
110
127
 
111
128
  context 'when git is not available' do
112
129
  before { Git.stub(:command_available?).and_return(false) }
113
130
  include_examples 'rewrites files'
131
+ include_examples 'does not generate commit message'
114
132
  end
115
133
 
116
134
  context "when the project's RSpec dependency is older than the required version" do
@@ -173,28 +191,6 @@ module Transpec
173
191
  end
174
192
  end
175
193
 
176
- context 'when -m/--generate-commit-message option is specified' do
177
- include_context 'inside of git repository'
178
-
179
- let(:args) { ['--force', '--generate-commit-message', file_path] }
180
-
181
- context 'and any conversion is done' do
182
- it 'writes commit message to .git/COMMIT_EDITMSG' do
183
- cli.run(args)
184
- File.read('.git/COMMIT_EDITMSG').should start_with('Convert specs')
185
- end
186
- end
187
-
188
- context 'and no conversion is done' do
189
- let(:file_content) { '' }
190
-
191
- it 'does not writes commit message' do
192
- cli.run(args)
193
- File.exist?('.git/COMMIT_EDITMSG').should be_false
194
- end
195
- end
196
- end
197
-
198
194
  context 'when -c/--rspec-command option is specified' do
199
195
  include_context 'inside of git repository'
200
196
 
@@ -4,12 +4,14 @@ require 'spec_helper'
4
4
  require 'transpec/commit_message'
5
5
  require 'transpec/report'
6
6
  require 'transpec/record'
7
+ require 'transpec/rspec_version'
7
8
 
8
9
  module Transpec
9
10
  describe CommitMessage do
10
- subject(:commit_message) { CommitMessage.new(report, cli_args) }
11
+ subject(:commit_message) { CommitMessage.new(report, rspec_version, cli_args) }
11
12
  let(:report) { Report.new }
12
- let(:cli_args) { %w(--force --generate-commit-message) }
13
+ let(:rspec_version) { RSpecVersion.new('2.99.0.beta1') }
14
+ let(:cli_args) { ['--force'] }
13
15
 
14
16
  before do
15
17
  report.records << Record.new('obj.stub(:message)', 'allow(obj).to receive(:message)')
@@ -28,7 +30,7 @@ module Transpec
28
30
 
29
31
  describe 'first line' do
30
32
  it 'has concise summary' do
31
- lines[0].chomp.should == 'Convert specs to the latest RSpec syntax with Transpec'
33
+ lines[0].chomp.should == 'Convert specs to RSpec 2.99.0.beta1 syntax with Transpec'
32
34
  end
33
35
  end
34
36
 
@@ -45,7 +47,7 @@ module Transpec
45
47
  body_lines[0].chomp
46
48
  .should match(/^This conversion is done by Transpec \d+\.\d+\.\d+ with the following command:$/)
47
49
  body_lines[1].chomp
48
- .should == ' transpec --force --generate-commit-message'
50
+ .should == ' transpec --force'
49
51
  end
50
52
 
51
53
  it 'has blank line after the preface' do
@@ -19,7 +19,6 @@ module Transpec
19
19
  [:parenthesize_matcher_arg?, true],
20
20
  [:forced?, false],
21
21
  [:skip_dynamic_analysis?, false],
22
- [:generate_commit_message?, false],
23
22
  [:negative_form_of_to, 'not_to'],
24
23
  [:boolean_matcher_type, :conditional],
25
24
  [:form_of_be_falsey, 'be_falsey']
@@ -40,23 +40,22 @@ module Transpec
40
40
  end
41
41
 
42
42
  describe '-m/--generate-commit-message option' do
43
- include_context 'isolated environment'
44
-
45
43
  let(:args) { ['--generate-commit-message'] }
46
44
 
47
- context 'when inside of git repository' do
48
- include_context 'inside of git repository'
45
+ before do
46
+ parser.stub(:warn)
47
+ end
49
48
 
50
- it 'sets Configuration#generate_commit_message? true' do
51
- parser.parse(args)
52
- configuration.generate_commit_message?.should be_true
49
+ it 'is deprecated' do
50
+ parser.should_receive(:warn) do |message|
51
+ message.should =~ /--generate-commit-message.+deprecated/i
53
52
  end
53
+
54
+ parser.parse(args)
54
55
  end
55
56
 
56
- context 'when not inside of git repository' do
57
- it 'raises error' do
58
- -> { parser.parse(args) }.should raise_error(/not in a Git repository/)
59
- end
57
+ it 'does not raise error' do
58
+ -> { parser.parse(args) }.should_not raise_error
60
59
  end
61
60
  end
62
61
 
@@ -469,9 +469,9 @@ module Transpec
469
469
  rewritten_source.should == expected_source
470
470
  end
471
471
 
472
- it 'adds record `lambda { }.should` -> `expect { }.to`' do
472
+ it "adds record `#{method} { }.should` -> `expect { }.to`" do
473
473
  should_object.expectize!
474
- record.original_syntax.should == 'lambda { }.should'
474
+ record.original_syntax.should == "#{method} { }.should"
475
475
  record.converted_syntax.should == 'expect { }.to'
476
476
  end
477
477
  end
@@ -28,7 +28,7 @@ class TranspecDemo < TranspecTest
28
28
  def run_demo(transpec_args = [])
29
29
  in_project_dir do
30
30
  with_clean_bundler_env do
31
- sh File.join(Transpec.root, 'bin', 'transpec'), '--force', '--generate-commit-message'
31
+ sh File.join(Transpec.root, 'bin', 'transpec'), '--force'
32
32
  sh 'bundle exec rspec'
33
33
  sh "git checkout --quiet -b #{DEMO_BRANCH}"
34
34
  sh 'git commit --all --file .git/COMMIT_EDITMSG'
metadata CHANGED
@@ -1,195 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transpec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rainbow
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.8'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '4.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '4.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '2.14'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.14'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '10.1'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '10.1'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0.7'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.7'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0.10'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.10'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: guard-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '4.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '4.0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: guard-rubocop
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '1.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: guard-shell
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ~>
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0.5'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ~>
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0.5'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: ruby_gntp
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ~>
185
+ - - "~>"
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0.3'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ~>
192
+ - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0.3'
195
195
  description: Transpec converts your specs to the latest RSpec syntax with static and
@@ -201,9 +201,9 @@ executables:
201
201
  extensions: []
202
202
  extra_rdoc_files: []
203
203
  files:
204
- - .gitignore
205
- - .rubocop.yml
206
- - .travis.yml
204
+ - ".gitignore"
205
+ - ".rubocop.yml"
206
+ - ".travis.yml"
207
207
  - CHANGELOG.md
208
208
  - Gemfile
209
209
  - Guardfile
@@ -310,12 +310,12 @@ require_paths:
310
310
  - lib
311
311
  required_ruby_version: !ruby/object:Gem::Requirement
312
312
  requirements:
313
- - - '>='
313
+ - - ">="
314
314
  - !ruby/object:Gem::Version
315
315
  version: '0'
316
316
  required_rubygems_version: !ruby/object:Gem::Requirement
317
317
  requirements:
318
- - - '>='
318
+ - - ">="
319
319
  - !ruby/object:Gem::Version
320
320
  version: '0'
321
321
  requirements: []
@@ -361,3 +361,4 @@ test_files:
361
361
  - spec/transpec/syntax/should_spec.rb
362
362
  - spec/transpec/util_spec.rb
363
363
  - spec/transpec_spec.rb
364
+ has_rdoc: