transpec 1.10.0 → 1.10.1

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: 6746cd9c37b13d9dcf9c77b423146988dc76fc05
4
- data.tar.gz: 9741bc313663316ea54b25eff57abce0aa3b8440
3
+ metadata.gz: 44ca6a93bd2bda16ddb06a1b392b577d4058e181
4
+ data.tar.gz: 157977020a4bff523c6e261722288b3f06d49bc1
5
5
  SHA512:
6
- metadata.gz: 8794a9d4a01800a80b7a7ab09c29418d2b27a55978263d655ea7f81ac8c2e7babbdacb306caef3a1086dba283c67bb7ec81b8a48267de1b3f3758eff7be57eeb
7
- data.tar.gz: 531aca6df23e26d22e048231c6393c044e13137d753924b568a25ee7e11a81d57271ac652c93e403001fd65cc23f79cb3de2f4710f7496fed39521b6277d10e1
6
+ metadata.gz: 7aa89e910659d73dbe0c62bf494041cb94997f5a1d0fad85e01773dc8ff31be766f6f4f138cc0ec228391dded032e0181a75d1ba6f6cb9cd619769218db867e0
7
+ data.tar.gz: 9c902ba46ea0940d3d418bf5f9e752d97b9d19797d3543da814e41f568115dc4e17d3f8e6b0d132dd3704d06f7fc02a7efcf5a6070cfdaaf4b0bddf438f91ba5
data/.travis.yml CHANGED
@@ -5,4 +5,4 @@ rvm:
5
5
  - 2.1.1
6
6
  - jruby
7
7
  before_install: gem update --remote bundler
8
- script: bundle exec rake travis
8
+ script: bundle exec rake ci
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v1.10.1
6
+
7
+ * Fix a bug where `expect(hash['some_key']).to have(2).items` was converted to `expect(hash[().size).to eq(2)` ([#51](https://github.com/yujinakayama/transpec/issues/51))
8
+
5
9
  ## v1.10.0
6
10
 
7
11
  * Support conversion of pending examples
@@ -130,7 +134,7 @@
130
134
 
131
135
  ## v0.2.5
132
136
 
133
- * Do not touch file if the source does need to be rewritten
137
+ * Do not touch file if the source does not need to be rewritten
134
138
 
135
139
  ## v0.2.4
136
140
 
data/Guardfile CHANGED
@@ -4,7 +4,7 @@
4
4
  # This group allows to skip running RuboCop if RSpec failed,
5
5
  # like Red > Green (RSpec) > Refactor (RuboCop).
6
6
  group :red_green_refactor, halt_on_fail: true do
7
- guard :rspec, all_on_start: true, failed_mode: :keep, cmd: 'bundle exec rspec' do
7
+ guard :rspec, all_on_start: true, cmd: 'bundle exec rspec' do
8
8
  watch(%r{^spec/.+_spec\.rb$})
9
9
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
10
10
  watch('spec/spec_helper.rb') { "spec" }
data/Rakefile CHANGED
@@ -11,4 +11,4 @@ end
11
11
 
12
12
  task default: %w(spec style readme)
13
13
 
14
- task travis: %w(spec style readme:check test:all)
14
+ task ci: %w(spec style readme:check test:all)
@@ -5,46 +5,6 @@ require 'parser'
5
5
  module Transpec
6
6
  module AST
7
7
  class Node < Parser::AST::Node
8
- TYPES = %w(
9
- true false nil
10
- int float
11
- str dstr
12
- sym dsym
13
- xstr
14
- regexp regopt
15
- array splat
16
- hash pair kwsplat
17
- irange erange
18
- self
19
- lvar ivar cvar gvar
20
- nth_ref back_ref
21
- const cbase
22
- defined?
23
- lvasgn ivasgn cvasgn gvasgn
24
- casgn
25
- masgn mlhs
26
- op_asgn or_asgn and_asgn
27
- module class sclass
28
- def defs undef
29
- alias
30
- args
31
- arg optarg restarg blockarg shadowarg kwarg kwoptarg kwrestarg
32
- send
33
- super zsuper
34
- yield
35
- block block_pass
36
- and or not
37
- if
38
- case when
39
- while until while_post until_post for
40
- break next redo return
41
- begin
42
- rescue resbody ensure retry
43
- preexe postexe
44
- iflipflop eflipflop
45
- match_current_line match_with_lvasgn
46
- ).map(&:to_sym).freeze
47
-
48
8
  attr_reader :metadata
49
9
 
50
10
  def initialize(type, children = [], properties = {})
@@ -59,7 +19,7 @@ module Transpec
59
19
  end
60
20
  end
61
21
 
62
- TYPES.each do |node_type|
22
+ Parser::Meta::NODE_TYPES.each do |node_type|
63
23
  method_name = "#{node_type.to_s.gsub(/\W/, '')}_type?"
64
24
  define_method(method_name) do
65
25
  type == node_type
@@ -55,7 +55,7 @@ module Transpec
55
55
  :green
56
56
  end
57
57
 
58
- convertion_incomplete_caution_stats(base_color) + error_stats(base_color)
58
+ conversion_incomplete_caution_stats(base_color) + error_stats(base_color)
59
59
  end
60
60
 
61
61
  def stats
@@ -93,7 +93,7 @@ module Transpec
93
93
  text << indentation + ' ' + colorize('to: ', :cyan) + record.converted_syntax + "\n"
94
94
  end
95
95
 
96
- def convertion_incomplete_caution_stats(color)
96
+ def conversion_incomplete_caution_stats(color)
97
97
  text = pluralize(records.count, 'conversion') + ', '
98
98
  text << pluralize(conversion_errors.count, 'incomplete') + ', '
99
99
  text << pluralize(annotation_count, 'caution') + ', '
@@ -52,7 +52,7 @@ module Transpec
52
52
 
53
53
  if node.send_type? && (arg_node = node.children[2])
54
54
  left_of_arg_range = map.selector.end.join(arg_node.loc.expression.begin)
55
- unless left_of_arg_range.source.include?('(')
55
+ if !map.selector.source.start_with?('[') && !left_of_arg_range.source.include?('(')
56
56
  relative_index = left_of_arg_range.begin_pos - map.expression.begin_pos
57
57
  source[relative_index, left_of_arg_range.length] = '('
58
58
  source << ')'
@@ -21,15 +21,16 @@ module Transpec
21
21
 
22
22
  def self.check_target_node_statically(node)
23
23
  node = node.parent_node if node == BE_NODE
24
- return false unless node && node.send_type?
25
- receiver_node, method_name, *_ = *node
26
- return false if receiver_node.nil?
27
- OPERATORS.include?(method_name)
24
+ super(node)
25
+ end
26
+
27
+ def self.target_method?(receiver_node, method_name)
28
+ !receiver_node.nil? && OPERATORS.include?(method_name)
28
29
  end
29
30
 
30
31
  define_dynamic_analysis_request do |rewriter|
31
32
  if method_name == :=~
32
- rewriter.register_request(arg_node, :arg_is_enumerable?, 'is_a?(Enumerable)')
33
+ rewriter.register_request(arg_node, :enumerable_arg?, 'is_a?(Enumerable)')
33
34
  end
34
35
  end
35
36
 
@@ -47,10 +48,10 @@ module Transpec
47
48
  case method_name
48
49
  when :==
49
50
  convert_to_eq!(parenthesize_arg)
50
- when :===, :<, :<=, :>, :>=
51
- convert_to_be_operator!
52
51
  when :=~
53
52
  convert_to_match!(parenthesize_arg)
53
+ else
54
+ convert_to_be_operator!
54
55
  end
55
56
  end
56
57
 
@@ -84,7 +85,7 @@ module Transpec
84
85
  def convert_to_match!(parenthesize_arg)
85
86
  handle_anterior_of_operator!
86
87
 
87
- if arg_is_enumerable?
88
+ if enumerable_arg?
88
89
  replace(selector_range, 'match_array')
89
90
  else
90
91
  replace(selector_range, 'match')
@@ -92,11 +93,11 @@ module Transpec
92
93
 
93
94
  parenthesize!(parenthesize_arg)
94
95
 
96
+ accurate = !enumerable_arg?.nil?
97
+
95
98
  # Need to register record after all source rewrites are done
96
99
  # to avoid false record when failed with overlapped rewrite.
97
- accurate = !arg_is_enumerable?.nil?
98
-
99
- if arg_is_enumerable?
100
+ if enumerable_arg?
100
101
  register_record('=~ [1, 2]', 'match_array([1, 2])', accurate)
101
102
  else
102
103
  register_record('=~ /pattern/', 'match(/pattern/)', accurate)
@@ -111,14 +112,14 @@ module Transpec
111
112
  end
112
113
  end
113
114
 
114
- def arg_is_enumerable?
115
+ def enumerable_arg?
115
116
  case arg_node.type
116
117
  when :array
117
118
  true
118
119
  when :regexp
119
120
  false
120
121
  else
121
- runtime_data[arg_node, :arg_is_enumerable?]
122
+ runtime_data[arg_node, :enumerable_arg?]
122
123
  end
123
124
  end
124
125
 
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 1
7
7
  MINOR = 10
8
- PATCH = 0
8
+ PATCH = 1
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -43,7 +43,7 @@ module Transpec
43
43
  # rubocop:disable LineLength
44
44
  let(:expected_source) do
45
45
  <<-END
46
- transpec_analyze((transpec_analyze((subject), self, "(string)_14_21", { :should_source_location => [:object, "method(:should).source_location"] }).should), self, "(string)_14_28", { :"=~_source_location" => [:object, "method(:=~).source_location"], :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] }) =~ transpec_analyze((<<-HEREDOC.gsub('foo', 'bar')), self, "(string)_32_61", { :arg_is_enumerable? => [:object, "is_a?(Enumerable)"] })
46
+ transpec_analyze((transpec_analyze((subject), self, "(string)_14_21", { :should_source_location => [:object, "method(:should).source_location"] }).should), self, "(string)_14_28", { :"=~_source_location" => [:object, "method(:=~).source_location"], :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] }) =~ transpec_analyze((<<-HEREDOC.gsub('foo', 'bar')), self, "(string)_32_61", { :enumerable_arg? => [:object, "is_a?(Enumerable)"] })
47
47
  foo
48
48
  HEREDOC
49
49
  END
@@ -1118,6 +1118,35 @@ module Transpec
1118
1118
  end
1119
1119
  end
1120
1120
 
1121
+ context "when it is `expect(hash['some_key']).to have(2).items` form" do
1122
+ let(:source) do
1123
+ <<-END
1124
+ describe 'example' do
1125
+ it 'has 2 items' do
1126
+ expect(hash['some_key']).to have(2).items
1127
+ end
1128
+ end
1129
+ END
1130
+ end
1131
+
1132
+ let(:expected_source) do
1133
+ <<-END
1134
+ describe 'example' do
1135
+ it 'has 2 items' do
1136
+ expect(hash['some_key'].size).to eq(2)
1137
+ end
1138
+ end
1139
+ END
1140
+ end
1141
+
1142
+ let(:have_object) { expect_object.have_matcher }
1143
+
1144
+ fit "converts into `expect(hash['some_key'].size).to eq(2)` form" do
1145
+ have_object.convert_to_standard_expectation!
1146
+ rewritten_source.should == expected_source
1147
+ end
1148
+ end
1149
+
1121
1150
  context 'when it is `it { should have(2).items }` form' do
1122
1151
  let(:source) do
1123
1152
  <<-END
@@ -157,6 +157,11 @@ module Transpec
157
157
  it 'converts into `pending; do_something_fail` form' do
158
158
  rewritten_source.should == expected_source
159
159
  end
160
+
161
+ it 'adds record `pending { do_something_fail }` -> `pending; do_something_fail`' do
162
+ record.original_syntax.should == 'pending { do_something_fail }'
163
+ record.converted_syntax.should == 'pending; do_something_fail'
164
+ end
160
165
  end
161
166
 
162
167
  context "when it is singleline `pending('some reason') { do_something_fail }` form" do
@@ -25,6 +25,10 @@ class TranspecDemo < TranspecTest
25
25
  git_branch_delete(DEMO_BRANCH) if git_local_branch_exist?(DEMO_BRANCH)
26
26
  end
27
27
 
28
+ def shallow_clone?
29
+ false
30
+ end
31
+
28
32
  def run_demo(transpec_args = [])
29
33
  in_project_dir do
30
34
  with_clean_bundler_env do
@@ -114,7 +114,10 @@ class TranspecTest
114
114
  def git_clone
115
115
  Dir.chdir(self.class.base_dir) do
116
116
  # Disabling checkout here to suppress "detached HEAD" warning.
117
- sh "git clone --no-checkout --depth 1 --branch #{ref} #{url}"
117
+ command = %w(git clone --no-checkout)
118
+ command.concat(%w(--depth 1)) if shallow_clone?
119
+ command.concat(['--branch', ref, url])
120
+ sh command.join(' ')
118
121
  end
119
122
 
120
123
  in_project_dir do
@@ -122,6 +125,10 @@ class TranspecTest
122
125
  end
123
126
  end
124
127
 
128
+ def shallow_clone?
129
+ true
130
+ end
131
+
125
132
  def bundle_install
126
133
  in_project_dir do
127
134
  with_clean_bundler_env do
data/transpec.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.required_ruby_version = '>= 1.9.3'
24
24
 
25
- spec.add_runtime_dependency 'parser', '>= 2.1.3', '< 3.0'
25
+ spec.add_runtime_dependency 'parser', '>= 2.1.6', '< 3.0'
26
26
  spec.add_runtime_dependency 'bundler', '~> 1.3'
27
27
  spec.add_runtime_dependency 'rainbow', '>= 1.99.1', '< 3.0'
28
28
  spec.add_runtime_dependency 'json', '~> 1.8'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transpec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.3
19
+ version: 2.1.6
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '3.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 2.1.3
29
+ version: 2.1.6
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'