transpec 0.0.1 → 0.0.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +9 -0
  4. data/Guardfile +4 -0
  5. data/README.md +102 -5
  6. data/README.md.erb +107 -0
  7. data/Rakefile +26 -5
  8. data/bin/transpec +1 -1
  9. data/lib/transpec/ast/scanner.rb +3 -0
  10. data/lib/transpec/ast/scope_stack.rb +2 -0
  11. data/lib/transpec/cli.rb +4 -0
  12. data/lib/transpec/rewriter.rb +14 -2
  13. data/lib/transpec/syntax.rb +36 -1
  14. data/lib/transpec/syntax/any_instanceable.rb +24 -0
  15. data/lib/transpec/syntax/be_close.rb +32 -0
  16. data/lib/transpec/syntax/double.rb +14 -8
  17. data/lib/transpec/syntax/expectizable.rb +20 -0
  18. data/lib/transpec/syntax/matcher.rb +16 -8
  19. data/lib/transpec/syntax/method_stub.rb +26 -40
  20. data/lib/transpec/syntax/send_node_syntax.rb +2 -4
  21. data/lib/transpec/syntax/should.rb +25 -16
  22. data/lib/transpec/syntax/should_receive.rb +32 -35
  23. data/lib/transpec/version.rb +1 -1
  24. data/spec/spec_helper.rb +8 -6
  25. data/spec/support/shared_context.rb +4 -0
  26. data/spec/transpec/ast/scanner_spec.rb +1 -1
  27. data/spec/transpec/ast/scope_stack_spec.rb +1 -0
  28. data/spec/transpec/cli_spec.rb +1 -0
  29. data/spec/transpec/configuration_spec.rb +1 -0
  30. data/spec/transpec/git_spec.rb +8 -0
  31. data/spec/transpec/rewriter_spec.rb +30 -0
  32. data/spec/transpec/syntax/be_close_spec.rb +50 -0
  33. data/spec/transpec/syntax/double_spec.rb +3 -2
  34. data/spec/transpec/syntax/matcher_spec.rb +1 -0
  35. data/spec/transpec/syntax/method_stub_spec.rb +1 -0
  36. data/spec/transpec/syntax/should_receive_spec.rb +1 -0
  37. data/spec/transpec/syntax/should_spec.rb +1 -0
  38. data/spec/transpec/util_spec.rb +1 -0
  39. data/transpec.gemspec +1 -0
  40. metadata +23 -3
  41. data/lib/transpec.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c98c4880892b0c69338d5a58b145fb47e6efbc14
4
- data.tar.gz: 27d7e201e95c233d9e13887a9d22642e99034952
3
+ metadata.gz: f3d0d724597250da7c8777978b0966f79bb8ef4a
4
+ data.tar.gz: d8cd06841df2954393cbe9ce26bb6d4b892fb8d7
5
5
  SHA512:
6
- metadata.gz: 265a268cf2858c97c587c561c58cb0b129951d6f8b69acec44ac652457ad9eb11ff01e25d506914f34661239e792c37b0e9443448a92f5587a219b43af37e4cd
7
- data.tar.gz: 901f0dcc5290387aec5377f3514c61134199351000621520090d35aecd46be78063239a47c66f7ca3cd414ef6182f7aba845b067761cce0ee6774e999bc4aef3
6
+ metadata.gz: eaf64a911679b0b2277c3643ee3e53a2b92b8ac3b0f8d5730f6a5399e4179114b0290c32b4c308968601884a47728f52f77d8babbfdafb3309407a8ef7e8dddd
7
+ data.tar.gz: 081bd5d3f7d4e0b91a7ec37754cee098c0fcc714862044304549daff2f2e263ecb3c0d3a120c1299e049d4dcdcd7750d4cc93d9d8e9b5cf548e3fd6f69b101c6
@@ -11,3 +11,7 @@ WordArray:
11
11
  # TODO
12
12
  Documentation:
13
13
  Enabled: false
14
+
15
+ # Currently IndentationWidth reports false positive offence around here document.
16
+ IndentationWidth:
17
+ Enabled: false
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.0.2
4
+
5
+ * Support conversion from `be_close(expected, delta)` to `be_within(delta).of(expected)`
6
+
7
+ ## v0.0.1
8
+
9
+ * Initial release
data/Guardfile CHANGED
@@ -12,3 +12,7 @@ guard :rubocop do
12
12
  watch(%r{.+\.rb$})
13
13
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
14
14
  end
15
+
16
+ guard :shell do
17
+ watch('README.md.erb') { `rake readme` }
18
+ end
data/README.md CHANGED
@@ -1,13 +1,96 @@
1
+ [![Gem Version](https://badge.fury.io/rb/transpec.png)](http://badge.fury.io/rb/transpec) [![Dependency Status](https://gemnasium.com/yujinakayama/transpec.png)](https://gemnasium.com/yujinakayama/transpec) [![Build Status](https://travis-ci.org/yujinakayama/transpec.png?branch=master)](https://travis-ci.org/yujinakayama/transpec) [![Coverage Status](https://coveralls.io/repos/yujinakayama/transpec/badge.png)](https://coveralls.io/r/yujinakayama/transpec) [![Code Climate](https://codeclimate.com/github/yujinakayama/transpec.png)](https://codeclimate.com/github/yujinakayama/transpec)
2
+
1
3
  # Transpec
2
4
 
3
5
  **Transpec** automatically converts your specs into latest [RSpec](http://rspec.info/) syntax with static analysis.
4
6
 
5
- See the following pages for new RSpec syntax:
7
+ This aims to facilitate smooth transition to RSpec 3.
8
+
9
+ See the following pages for the new RSpec syntax and the plan for RSpec 3:
6
10
 
7
11
  * [Myron Marston » RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)
8
12
  * [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
9
13
  * [Myron Marston » The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3)
10
14
 
15
+ Note that Transpec does not yet support all conversions for the RSpec changes,
16
+ and also the changes for RSpec 3 is not fixed and may vary in the future.
17
+ So it's recommended to follow updates of both RSpec and Transpec.
18
+
19
+ ## Example
20
+
21
+ Here's an example spec:
22
+
23
+ ```ruby
24
+ describe Account do
25
+ subject(:account) { Account.new(logger) }
26
+ let(:logger) { mock('logger') }
27
+
28
+ describe '#balance' do
29
+ context 'initially' do
30
+ it 'is zero' do
31
+ account.balance.should == 0
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#close' do
37
+ it 'logs an account closed message' do
38
+ logger.should_receive(:account_closed).with(account)
39
+ account.close
40
+ end
41
+ end
42
+
43
+ describe '#renew' do
44
+ context 'when the account is renewable and not closed' do
45
+ before do
46
+ account.stub(:renewable? => true, :closed? => false)
47
+ end
48
+
49
+ it 'does not raise error' do
50
+ lambda { account.renew }.should_not raise_error
51
+ end
52
+ end
53
+ end
54
+ end
55
+ ```
56
+
57
+ Transpec would convert it to the following form:
58
+
59
+ ```ruby
60
+ describe Account do
61
+ subject(:account) { Account.new(logger) }
62
+ let(:logger) { double('logger') }
63
+
64
+ describe '#balance' do
65
+ context 'initially' do
66
+ it 'is zero' do
67
+ expect(account.balance).to eq(0)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#close' do
73
+ it 'logs an account closed message' do
74
+ expect(logger).to receive(:account_closed).with(account)
75
+ account.close
76
+ end
77
+ end
78
+
79
+ describe '#renew' do
80
+ context 'when the account is renewable and not closed' do
81
+ before do
82
+ allow(account).to receive(:renewable?).and_return(true)
83
+ allow(account).to receive(:closed?).and_return(false)
84
+ end
85
+
86
+ it 'does not raise error' do
87
+ expect { account.renew }.not_to raise_error
88
+ end
89
+ end
90
+ end
91
+ end
92
+ ```
93
+
11
94
  ## Installation
12
95
 
13
96
  ```bash
@@ -16,17 +99,31 @@ $ gem install transpec
16
99
 
17
100
  ## Basic Usage
18
101
 
19
- Run `transpec` with no arguments in your project directory:
102
+ Before converting your specs:
103
+
104
+ * Make sure your project has `rspec` gem dependency `2.14` or later. If not, change your `*.gemspec` or `Gemfile` to do so.
105
+ * Run `rspec` and check if all the specs pass.
106
+
107
+ Then, run `transpec` with no arguments in the project root directory:
20
108
 
21
109
  ```bash
110
+ $ cd some-project
22
111
  $ transpec
112
+ Processing spec/spec_helper.rb
113
+ Processing spec/spec_spec.rb
114
+ Processing spec/support/file_helper.rb
115
+ Processing spec/support/shared_context.rb
116
+ Processing spec/transpec/ast/scanner_spec.rb
117
+ Processing spec/transpec/ast/scope_stack_spec.rb
23
118
  ```
24
119
 
25
- This will inspect and overwrite all spec files in the `spec` directory.
120
+ This will convert and overwrite all spec files in the `spec` directory.
121
+
122
+ After the conversion, run `rspec` again and check if all pass.
26
123
 
27
- For more information, please see the help with `--help` option.
124
+ ## Compatibility
28
125
 
29
- **TODO:** Add more description
126
+ Tested on MRI 1.9, MRI 2.0 and JRuby in 1.9 mode.
30
127
 
31
128
  ## Contributing
32
129
 
@@ -0,0 +1,107 @@
1
+ [![Gem Version](https://badge.fury.io/rb/transpec.png)](http://badge.fury.io/rb/transpec) [![Dependency Status](https://gemnasium.com/yujinakayama/transpec.png)](https://gemnasium.com/yujinakayama/transpec) [![Build Status](https://travis-ci.org/yujinakayama/transpec.png?branch=master)](https://travis-ci.org/yujinakayama/transpec) [![Coverage Status](https://coveralls.io/repos/yujinakayama/transpec/badge.png)](https://coveralls.io/r/yujinakayama/transpec) [![Code Climate](https://codeclimate.com/github/yujinakayama/transpec.png)](https://codeclimate.com/github/yujinakayama/transpec)
2
+
3
+ # Transpec
4
+
5
+ **Transpec** automatically converts your specs into latest [RSpec](http://rspec.info/) syntax with static analysis.
6
+
7
+ This aims to facilitate smooth transition to RSpec 3.
8
+
9
+ See the following pages for the new RSpec syntax and the plan for RSpec 3:
10
+
11
+ * [Myron Marston » RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)
12
+ * [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
13
+ * [Myron Marston » The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3)
14
+
15
+ Note that Transpec does not yet support all conversions for the RSpec changes,
16
+ and also the changes for RSpec 3 is not fixed and may vary in the future.
17
+ So it's recommended to follow updates of both RSpec and Transpec.
18
+
19
+ ## Example
20
+
21
+ Here's an example spec:
22
+
23
+ ```ruby
24
+ <%=
25
+ example = <<END
26
+ describe Account do
27
+ subject(:account) { Account.new(logger) }
28
+ let(:logger) { mock('logger') }
29
+
30
+ describe '#balance' do
31
+ context 'initially' do
32
+ it 'is zero' do
33
+ account.balance.should == 0
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#close' do
39
+ it 'logs an account closed message' do
40
+ logger.should_receive(:account_closed).with(account)
41
+ account.close
42
+ end
43
+ end
44
+
45
+ describe '#renew' do
46
+ context 'when the account is renewable and not closed' do
47
+ before do
48
+ account.stub(:renewable? => true, :closed? => false)
49
+ end
50
+
51
+ it 'does not raise error' do
52
+ lambda { account.renew }.should_not raise_error
53
+ end
54
+ end
55
+ end
56
+ end
57
+ END
58
+ -%>
59
+ ```
60
+
61
+ Transpec would convert it to the following form:
62
+
63
+ ```ruby
64
+ <%= Transpec::Rewriter.new.rewrite(example) -%>
65
+ ```
66
+
67
+ ## Installation
68
+
69
+ ```bash
70
+ $ gem install transpec
71
+ ```
72
+
73
+ ## Basic Usage
74
+
75
+ Before converting your specs:
76
+
77
+ * Make sure your project has `rspec` gem dependency `<%= rspec_version %>` or later. If not, change your `*.gemspec` or `Gemfile` to do so.
78
+ * Run `rspec` and check if all the specs pass.
79
+
80
+ Then, run `transpec` with no arguments in the project root directory:
81
+
82
+ ```bash
83
+ $ cd some-project
84
+ $ transpec
85
+ Processing spec/spec_helper.rb
86
+ Processing spec/spec_spec.rb
87
+ Processing spec/support/file_helper.rb
88
+ Processing spec/support/shared_context.rb
89
+ Processing spec/transpec/ast/scanner_spec.rb
90
+ Processing spec/transpec/ast/scope_stack_spec.rb
91
+ ```
92
+
93
+ This will convert and overwrite all spec files in the `spec` directory.
94
+
95
+ After the conversion, run `rspec` again and check if all pass.
96
+
97
+ ## Compatibility
98
+
99
+ Tested on MRI 1.9, MRI 2.0 and JRuby in 1.9 mode.
100
+
101
+ ## Contributing
102
+
103
+ 1. Fork it
104
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
105
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
106
+ 4. Push to the branch (`git push origin my-new-feature`)
107
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ Rubocop::RakeTask.new(:style)
5
7
 
6
8
  namespace :ci do
7
9
  desc "#{Rake::Task['spec'].comment} for CI environment"
@@ -16,12 +18,31 @@ namespace :ci do
16
18
  end
17
19
  end
18
20
 
19
- desc 'Check code style with RuboCop'
20
- task :style do
21
- sh('rubocop')
22
- end
23
-
24
21
  desc 'Run RSpec and RuboCop'
25
22
  task all: [:spec, :style]
26
23
 
24
+ desc 'Generate README.md'
25
+ task :readme do
26
+ require 'erb'
27
+ require 'transpec'
28
+
29
+ gem_specification = Gem::Specification.load('transpec.gemspec')
30
+ rspec_dependency = gem_specification.dependencies.find { |d| d.name == 'rspec' }
31
+ rspec_requirement = rspec_dependency.requirement
32
+ rspec_version = rspec_requirement.requirements.first.find { |r| r.is_a?(Gem::Version) }
33
+
34
+ erb = ERB.new(File.read('README.md.erb'), nil, '-')
35
+ content = erb.result(binding)
36
+ File.write('README.md', content)
37
+ end
38
+
39
+ task :abort_unless_latest_readme_is_committed => :readme do
40
+ unless Transpec::Git.clean?
41
+ warn 'Commit README.md before release.'
42
+ exit 1
43
+ end
44
+ end
45
+
46
+ Rake::Task[:release].enhance([:abort_unless_latest_readme_is_committed])
47
+
27
48
  task default: :all
@@ -2,7 +2,7 @@
2
2
  # coding: utf-8
3
3
 
4
4
  $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
5
- require 'transpec'
5
+ require 'transpec/cli'
6
6
 
7
7
  result = Transpec::CLI.run
8
8
  exit(result ? 0 : 1)
@@ -1,5 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'transpec/ast/scope_stack'
4
+ require 'parser'
5
+
3
6
  module Transpec
4
7
  module AST
5
8
  class Scanner
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'transpec/util'
4
+
3
5
  module Transpec
4
6
  module AST
5
7
  class ScopeStack < Array
@@ -1,5 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'transpec/configuration'
4
+ require 'transpec/git'
5
+ require 'transpec/rewriter'
6
+ require 'transpec/version'
3
7
  require 'optparse'
4
8
  require 'find'
5
9
 
@@ -1,6 +1,14 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'parser'
3
+ require 'transpec/ast/scanner'
4
+ require 'transpec/configuration'
5
+ require 'transpec/syntax'
6
+ require 'transpec/syntax/be_close'
7
+ require 'transpec/syntax/double'
8
+ require 'transpec/syntax/matcher'
9
+ require 'transpec/syntax/method_stub'
10
+ require 'transpec/syntax/should'
11
+ require 'transpec/syntax/should_receive'
4
12
  require 'parser/current'
5
13
 
6
14
  module Transpec
@@ -95,7 +103,7 @@ module Transpec
95
103
  end
96
104
 
97
105
  def process_double(double)
98
- double.replace_deprecated_method! if @configuration.replace_deprecated_method?
106
+ double.convert_to_double! if @configuration.replace_deprecated_method?
99
107
  end
100
108
 
101
109
  def process_method_stub(method_stub)
@@ -105,5 +113,9 @@ module Transpec
105
113
  method_stub.replace_deprecated_method!
106
114
  end
107
115
  end
116
+
117
+ def process_be_close(be_close)
118
+ be_close.convert_to_be_within! if @configuration.replace_deprecated_method?
119
+ end
108
120
  end
109
121
  end
@@ -41,7 +41,10 @@ module Transpec
41
41
  end
42
42
 
43
43
  def self.target_node?(node)
44
- false
44
+ return false unless node.type == :send
45
+ receiver_node, method_name, *_ = *node
46
+ return false unless target_receiver_node?(receiver_node)
47
+ target_method_names.include?(method_name)
45
48
  end
46
49
 
47
50
  def initialize(node, ancestor_nodes, in_example_group_context, source_rewriter)
@@ -54,5 +57,37 @@ module Transpec
54
57
  def parent_node
55
58
  @ancestor_nodes.last
56
59
  end
60
+
61
+ def expression_range
62
+ @node.loc.expression
63
+ end
64
+
65
+ protected
66
+
67
+ def self.target_receiver_node?(node)
68
+ false
69
+ end
70
+
71
+ def self.target_method_names
72
+ []
73
+ end
74
+
75
+ private
76
+
77
+ def remove(range)
78
+ @source_rewriter.remove(range)
79
+ end
80
+
81
+ def insert_before(range, content)
82
+ @source_rewriter.insert_before(range, content)
83
+ end
84
+
85
+ def insert_after(range, content)
86
+ @source_rewriter.insert_after(range, content)
87
+ end
88
+
89
+ def replace(range, content)
90
+ @source_rewriter.replace(range, content)
91
+ end
57
92
  end
58
93
  end