transpec 2.0.0 → 2.1.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: c55138d0f6562f6e88f54a665a1606ff3b69f97d
4
- data.tar.gz: ad436da74d347b87d8e5e96adebf45f2e8c9bc29
3
+ metadata.gz: 2402b33bb816bb8834d369cd49ea5b93199f0c7f
4
+ data.tar.gz: 3fc7140d2ebbf711de884459b1a8d424ce073a1f
5
5
  SHA512:
6
- metadata.gz: d194a5757be5ebad5680322636fb28e4acb2179421d89b018a3e40965a5712c8395aa8a2130e6bb13e6e74a32d9da4785f458f5cc4c7a4b041a3b169c793040a
7
- data.tar.gz: 82630e3bab603645603d56cf8d272e8a5ced283989ee1e59bfb3fba43cb78738d6563d11ac645d6d49dda62391da6f88b44b06afc8673335be7518cdadd145d8
6
+ metadata.gz: e023997e0b62507e833df7fe92a7fad689c2aa6fc601378df904e54d66d8122ea97af22eec4ca8c0c901aa043c7717221188dba3871828e0822e104b4d6e93f2
7
+ data.tar.gz: 1c2c697e5f2d143be79ecc6d8718e488466eb3f53c3d9629fd94c447529ab5c0c1423f4333c28b6af07f4a657aac48b37d291a25e69dde1b01b51ad0699f6ca9
data/.rubocop.yml CHANGED
@@ -55,3 +55,7 @@ BracesAroundHashParameters:
55
55
  # TODO: Shorten to 100.
56
56
  ClassLength:
57
57
  Max: 137
58
+
59
+ # This cop should consider symmetries.
60
+ GuardClause:
61
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v2.1.0
6
+
7
+ * Disable invalid conversion of `expect(model).to have(n).errors_on(:attr)`. ([#62](https://github.com/yujinakayama/transpec/issues/62))
8
+ * Fix false positive conversion of `expect { }.should raise_error(SpecificErrorClass)`. ([#64](https://github.com/yujinakayama/transpec/issues/64))
9
+ * Support conversion of `expect { do_something }.should`.
10
+ * Relax `activesupport` dependency from `'~> 4.0'` to `'>= 3.0', '< 5.0'` in case that `transpec` is added to a `Gemfile`. ([#63](https://github.com/yujinakayama/transpec/pull/63))
11
+
5
12
  ## v2.0.0
6
13
 
7
14
  * Support conversion of implicit spec types in rspec-rails. ([#57](https://github.com/yujinakayama/transpec/issues/57))
data/README.md CHANGED
@@ -639,6 +639,9 @@ expect(team).to have(3).players
639
639
 
640
640
  # Assume #players is a private method.
641
641
  expect(team).to have(3).players
642
+
643
+ # Validation expectations in rspec-rails.
644
+ expect(model).to have(2).errors_on(:name)
642
645
  ```
643
646
 
644
647
  Will be converted to:
@@ -656,6 +659,9 @@ expect(team.players.size).to eq(3)
656
659
 
657
660
  # have(n).items matcher invokes #players even if it's a private method.
658
661
  expect(team.send(:players).size).to eq(3)
662
+
663
+ # Conversion of `have(n).errors_on(:attr)` is not supported.
664
+ expect(model).to have(2).errors_on(:name)
659
665
  ```
660
666
 
661
667
  There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) which is a gem extracted from `rspec-expectations`.
@@ -664,7 +670,25 @@ If you choose to do so, disable this conversion by either:
664
670
  * Specify `--keep have_items` option manually.
665
671
  * Require `rspec-collection_matchers` in your spec so that Transpec automatically disables this conversion.
666
672
 
667
- ---
673
+ #### Note about `expect(model).to have(n).errors_on(:attr)`
674
+
675
+ The idiom `expect(model).to have(n).errors_on(:attr)` in rspec-rails 2 consists of
676
+ `have(n).items` matcher and a monkey-patch [`ActiveModel::Validations#errors_on`](https://github.com/rspec/rspec-rails/blob/v2.14.2/lib/rspec/rails/extensions/active_record/base.rb#L34-L57).
677
+ In RSpec 2 the monkey-patch was provided by rspec-rails,
678
+ but in RSpec 3 it's extracted to rspec-collection_matchers along with `have(n).items` matcher.
679
+ So if you convert it to `expect(model.errors_on(:attr).size).to eq(2)` without rspec-collection_matchers,
680
+ it fails with error `undefined method 'error_on' for #<Model ...>`.
681
+
682
+ Technically it can be converted to:
683
+
684
+ ```ruby
685
+ model.valid?
686
+ expect(model.errors[:attr].size).to eq(n)
687
+ ```
688
+
689
+ However currently Transpec doesn't support this conversion
690
+ since this is probably not what most people want.
691
+ So using rspec-collection_matchers gem is recommended for now.
668
692
 
669
693
  * This conversion can be disabled by: `--keep have_items`
670
694
  * Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
data/README.md.erb CHANGED
@@ -640,6 +640,13 @@ private_method_example = <<END
640
640
  expect(team).to have(3).players
641
641
  END
642
642
  -%>
643
+
644
+ # Validation expectations in rspec-rails.
645
+ <%=
646
+ errors_on_example = <<END
647
+ expect(model).to have(2).errors_on(:name)
648
+ END
649
+ -%>
643
650
  ```
644
651
 
645
652
  Will be converted to:
@@ -680,6 +687,36 @@ end
680
687
  team = Team.new
681
688
  END
682
689
  -%>
690
+
691
+ # Conversion of `have(n).errors_on(:attr)` is not supported.
692
+ <%=
693
+ convert(errors_on_example, dynamic: true, wrap_with: :example, hidden: <<END)
694
+ module ActiveModel
695
+ module Validations
696
+ def errors_on(attribute, options = {})
697
+ valid_args = [options[:context]].compact
698
+ self.valid?(*valid_args)
699
+
700
+ [self.errors[attribute]].flatten.compact
701
+ end
702
+ end
703
+ end
704
+
705
+ class Model
706
+ include ActiveModel::Validations
707
+
708
+ def valid?(*)
709
+ false
710
+ end
711
+
712
+ def errors
713
+ { name: [:foo, :bar] }
714
+ end
715
+ end
716
+
717
+ model = Model.new
718
+ END
719
+ -%>
683
720
  ```
684
721
 
685
722
  There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) which is a gem extracted from `rspec-expectations`.
@@ -688,7 +725,25 @@ If you choose to do so, disable this conversion by either:
688
725
  * Specify `--keep have_items` option manually.
689
726
  * Require `rspec-collection_matchers` in your spec so that Transpec automatically disables this conversion.
690
727
 
691
- ---
728
+ #### Note about `expect(model).to have(n).errors_on(:attr)`
729
+
730
+ The idiom `expect(model).to have(n).errors_on(:attr)` in rspec-rails 2 consists of
731
+ `have(n).items` matcher and a monkey-patch [`ActiveModel::Validations#errors_on`](https://github.com/rspec/rspec-rails/blob/v2.14.2/lib/rspec/rails/extensions/active_record/base.rb#L34-L57).
732
+ In RSpec 2 the monkey-patch was provided by rspec-rails,
733
+ but in RSpec 3 it's extracted to rspec-collection_matchers along with `have(n).items` matcher.
734
+ So if you convert it to `expect(model.errors_on(:attr).size).to eq(2)` without rspec-collection_matchers,
735
+ it fails with error `undefined method 'error_on' for #<Model ...>`.
736
+
737
+ Technically it can be converted to:
738
+
739
+ ```ruby
740
+ model.valid?
741
+ expect(model.errors[:attr].size).to eq(n)
742
+ ```
743
+
744
+ However currently Transpec doesn't support this conversion
745
+ since this is probably not what most people want.
746
+ So using rspec-collection_matchers gem is recommended for now.
692
747
 
693
748
  * This conversion can be disabled by: `--keep have_items`
694
749
  * Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
@@ -1,11 +1,11 @@
1
1
  module TranspecAnalysis
2
2
  @base_path = Dir.pwd
3
3
 
4
- def self.global_data
4
+ def self.temporary_data
5
5
  @data ||= {}
6
6
  end
7
7
 
8
- def self.node_data
8
+ def self.data
9
9
  @data ||= {}
10
10
  end
11
11
 
@@ -18,7 +18,7 @@ module TranspecAnalysis
18
18
  require 'json'
19
19
  path = File.join(@base_path, '<%= RESULT_FILE %>')
20
20
  File.open(path, 'w') do |file|
21
- JSON.dump(node_data, file)
21
+ JSON.dump(data, file)
22
22
  end
23
23
  end
24
24
  end
@@ -38,7 +38,7 @@ def <%= ANALYSIS_METHOD %>(object, context, node_id, analysis_codes)
38
38
  end
39
39
  end
40
40
 
41
- TranspecAnalysis.node_data[node_id] = node_data
41
+ TranspecAnalysis.data[node_id] = node_data
42
42
 
43
43
  object
44
44
  end
@@ -59,7 +59,7 @@ module Transpec
59
59
  :green
60
60
  end
61
61
 
62
- conversion_incomplete_caution_stats(base_color) + error_stats(base_color)
62
+ conversion_incomplete_warning_stats(base_color) + error_stats(base_color)
63
63
  end
64
64
 
65
65
  def stats
@@ -97,10 +97,10 @@ module Transpec
97
97
  text << indentation + ' ' + colorize('to: ', :cyan) + record.converted_syntax + "\n"
98
98
  end
99
99
 
100
- def conversion_incomplete_caution_stats(color)
100
+ def conversion_incomplete_warning_stats(color)
101
101
  text = pluralize(records.count, 'conversion') + ', '
102
102
  text << pluralize(conversion_errors.count, 'incomplete') + ', '
103
- text << pluralize(annotation_count, 'caution') + ', '
103
+ text << pluralize(annotation_count, 'warning') + ', '
104
104
  colorize(text, color)
105
105
  end
106
106
 
@@ -29,7 +29,9 @@ module Transpec
29
29
  end
30
30
 
31
31
  def conversion_target?
32
- super && !runtime_subject_data(:project_requires_collection_matcher?)
32
+ return false unless super
33
+ return false if runtime_subject_data(:project_requires_collection_matcher?)
34
+ !active_model_errors_on?
33
35
  end
34
36
 
35
37
  def convert_to_standard_expectation!(parenthesize_matcher_arg = true)
@@ -70,6 +72,11 @@ module Transpec
70
72
  runtime_subject_data(:collection_accessor)
71
73
  end
72
74
 
75
+ def active_model_errors_on?
76
+ return false unless runtime_subject_data(:subject_includes_active_model_validations?)
77
+ [:errors_on, :error_on].include?(items_name)
78
+ end
79
+
73
80
  def collection_accessor_is_private?
74
81
  runtime_subject_data(:collection_accessor_is_private?)
75
82
  end
@@ -29,6 +29,10 @@ module Transpec
29
29
  code = "#{subject_code}.private_methods.include?(#{items_name.inspect})"
30
30
  rewriter.register_request(target_node, key, code, target_type)
31
31
 
32
+ key = :subject_includes_active_model_validations?
33
+ code = 'is_a?(ActiveModel::Validations)'
34
+ rewriter.register_request(target_node, key, code, target_type)
35
+
32
36
  key = :project_requires_collection_matcher?
33
37
  code = 'defined?(RSpec::CollectionMatchers)'
34
38
  rewriter.register_request(target_node, key, code, :context)
@@ -27,7 +27,8 @@ module Transpec
27
27
 
28
28
  def positive?
29
29
  to_method_name = to_node.children[1]
30
- to_method_name == :to
30
+ # `expect { do_something }.should raise_error` is possible in RSpec 2.
31
+ [:to, :should].include?(to_method_name)
31
32
  end
32
33
 
33
34
  def subject_node
@@ -5,6 +5,8 @@ require 'transpec/syntax/mixin/should_base'
5
5
  require 'transpec/rspec_dsl'
6
6
  require 'transpec/util'
7
7
  require 'active_support/inflector/methods'
8
+ require 'active_support/inflector/inflections'
9
+ require 'active_support/inflections'
8
10
 
9
11
  module Transpec
10
12
  class Syntax
@@ -15,8 +15,8 @@ module Transpec
15
15
  include Mixin::Send, Mixin::RSpecRails, ConfigModification
16
16
 
17
17
  define_dynamic_analysis do |rewriter|
18
- code = "TranspecAnalysis.global_data[:rspec_configure_run_order] ||= 0\n" \
19
- 'TranspecAnalysis.global_data[:rspec_configure_run_order] += 1'
18
+ code = "TranspecAnalysis.temporary_data[:rspec_configure_run_order] ||= 0\n" \
19
+ 'TranspecAnalysis.temporary_data[:rspec_configure_run_order] += 1'
20
20
  rewriter.register_request(node, :run_order, code)
21
21
  end
22
22
 
@@ -30,14 +30,10 @@ module Transpec
30
30
  super && receiver_node && [:should, :should_not].include?(method_name)
31
31
  end
32
32
 
33
- def expect_available?
34
- syntax_available?(__method__)
35
- end
36
-
37
33
  def expectize!(negative_form = 'not_to')
38
34
  fail ContextError.new("##{method_name}", '#expect', selector_range) unless expect_available?
39
35
 
40
- if proc_literal?(subject_node)
36
+ if proc_subject?
41
37
  replace(range_of_subject_method_taking_block, 'expect')
42
38
  else
43
39
  wrap_subject_in_expect!
@@ -51,13 +47,25 @@ module Transpec
51
47
 
52
48
  private
53
49
 
50
+ def expect_available?
51
+ syntax_available?(__method__)
52
+ end
53
+
54
+ def proc_subject?
55
+ return true if proc_literal?(subject_node)
56
+ return false unless subject_node.block_type?
57
+ send_node = subject_node.children.first
58
+ receiver_node, method_name, = *send_node
59
+ receiver_node.nil? && method_name == :expect
60
+ end
61
+
54
62
  def range_of_subject_method_taking_block
55
63
  send_node = subject_node.children.first
56
64
  send_node.loc.expression
57
65
  end
58
66
 
59
67
  def register_record(negative_form_of_to)
60
- if proc_literal?(subject_node)
68
+ if proc_subject?
61
69
  original_syntax = "#{range_of_subject_method_taking_block.source} { }.should"
62
70
  converted_syntax = 'expect { }.'
63
71
  else
@@ -4,7 +4,7 @@ module Transpec
4
4
  # http://semver.org/
5
5
  module Version
6
6
  MAJOR = 2
7
- MINOR = 0
7
+ MINOR = 1
8
8
  PATCH = 0
9
9
 
10
10
  def self.to_s
@@ -81,7 +81,7 @@ module Transpec
81
81
 
82
82
  describe '#stats' do
83
83
  it 'returns stats string' do
84
- report.stats.should == '3 conversions, 1 incomplete, 2 cautions, 0 errors'
84
+ report.stats.should == '3 conversions, 1 incomplete, 2 warnings, 0 errors'
85
85
  end
86
86
  end
87
87
 
@@ -231,10 +231,9 @@ module Transpec
231
231
  end
232
232
 
233
233
  let(:current_example_objects) do
234
- ast.each_node.reduce([]) do |objects, node|
234
+ ast.each_node.each_with_object([]) do |node, objects|
235
235
  current_example_object = CurrentExample.new(node, source_rewriter, runtime_data)
236
236
  objects << current_example_object if current_example_object.conversion_target?
237
- objects
238
237
  end
239
238
  end
240
239
 
@@ -139,6 +139,81 @@ module Transpec
139
139
  it { should be_false }
140
140
  end
141
141
  end
142
+
143
+ context 'with expression `expect(obj).to have(2).errors_on(:name)`' do
144
+ subject { expect_object.have_matcher.conversion_target? }
145
+
146
+ context 'and subject includes ActiveModel::Validations' do
147
+ let(:source) do
148
+ <<-END
149
+ module ActiveModel
150
+ module Validations
151
+ def errors_on(attribute, options = {})
152
+ valid_args = [options[:context]].compact
153
+ self.valid?(*valid_args)
154
+
155
+ [self.errors[attribute]].flatten.compact
156
+ end
157
+ end
158
+ end
159
+
160
+ class SomeModel
161
+ include ActiveModel::Validations
162
+
163
+ def valid?(*)
164
+ false
165
+ end
166
+
167
+ def errors
168
+ { name: [:foo, :bar] }
169
+ end
170
+ end
171
+
172
+ describe SomeModel do
173
+ it 'has 2 errors on name' do
174
+ expect(subject).to have(2).errors_on(:name)
175
+ end
176
+ end
177
+ END
178
+ end
179
+
180
+ context 'without runtime information' do
181
+ it { should be_true }
182
+ end
183
+
184
+ context 'with runtime information' do
185
+ include_context 'dynamic analysis objects'
186
+ it { should be_false }
187
+ end
188
+ end
189
+
190
+ context 'and subject includes ActiveModel::Validations' do
191
+ let(:source) do
192
+ <<-END
193
+ class SomeModel
194
+ def errors_on(*)
195
+ [:foo, :bar]
196
+ end
197
+ end
198
+
199
+ describe SomeModel do
200
+ it 'has 2 errors on name' do
201
+ expect(subject).to have(2).errors_on(:name)
202
+ end
203
+ end
204
+ END
205
+ end
206
+
207
+ context 'without runtime information' do
208
+ it { should be_true }
209
+ end
210
+
211
+ context 'with runtime information' do
212
+ include_context 'dynamic analysis objects'
213
+ it { should be_true }
214
+ end
215
+ end
216
+ end
142
217
  end
143
218
 
144
219
  describe '#convert_to_standard_expectation!' do
@@ -931,24 +1006,24 @@ module Transpec
931
1006
  end
932
1007
  end
933
1008
 
934
- context 'with expression `expect(obj).to have(2).errors_on(:name)`' do
1009
+ context 'with expression `expect(obj).to have(2).attrs_on(:name)`' do
935
1010
  let(:have_object) { expect_object.have_matcher }
936
1011
 
937
1012
  context 'with runtime information' do
938
1013
  include_context 'dynamic analysis objects'
939
1014
 
940
- context 'and subject responds to #errors_on' do
1015
+ context 'and subject responds to #attrs_on' do
941
1016
  let(:source) do
942
1017
  <<-END
943
1018
  class SomeModel
944
- def errors_on(attribute)
1019
+ def attrs_on(attribute)
945
1020
  [:foo, :bar]
946
1021
  end
947
1022
  end
948
1023
 
949
1024
  describe SomeModel do
950
- it 'has 2 errors on name' do
951
- expect(subject).to have(2).errors_on(:name)
1025
+ it 'has 2 attributes on name' do
1026
+ expect(subject).to have(2).attrs_on(:name)
952
1027
  end
953
1028
  end
954
1029
  END
@@ -957,46 +1032,46 @@ module Transpec
957
1032
  let(:expected_source) do
958
1033
  <<-END
959
1034
  class SomeModel
960
- def errors_on(attribute)
1035
+ def attrs_on(attribute)
961
1036
  [:foo, :bar]
962
1037
  end
963
1038
  end
964
1039
 
965
1040
  describe SomeModel do
966
- it 'has 2 errors on name' do
967
- expect(subject.errors_on(:name).size).to eq(2)
1041
+ it 'has 2 attributes on name' do
1042
+ expect(subject.attrs_on(:name).size).to eq(2)
968
1043
  end
969
1044
  end
970
1045
  END
971
1046
  end
972
1047
 
973
- it 'converts to `expect(obj.errors_on(:name).size).to eq(2)` form' do
1048
+ it 'converts to `expect(obj.attrs_on(:name).size).to eq(2)` form' do
974
1049
  have_object.convert_to_standard_expectation!
975
1050
  rewritten_source.should == expected_source
976
1051
  end
977
1052
 
978
1053
  it 'adds record ' \
979
- '`expect(obj).to have(n).errors_on(...)` -> `expect(obj.errors_on(...).size).to eq(n)`' do
1054
+ '`expect(obj).to have(n).attrs_on(...)` -> `expect(obj.attrs_on(...).size).to eq(n)`' do
980
1055
  have_object.convert_to_standard_expectation!
981
- record.original_syntax.should == 'expect(obj).to have(n).errors_on(...)'
982
- record.converted_syntax.should == 'expect(obj.errors_on(...).size).to eq(n)'
1056
+ record.original_syntax.should == 'expect(obj).to have(n).attrs_on(...)'
1057
+ record.converted_syntax.should == 'expect(obj.attrs_on(...).size).to eq(n)'
983
1058
  end
984
1059
  end
985
1060
 
986
- context 'and #errors_on is a private method' do
1061
+ context 'and #attrs_on is a private method' do
987
1062
  let(:source) do
988
1063
  <<-END
989
1064
  class SomeModel
990
1065
  private
991
1066
 
992
- def errors_on(attribute)
1067
+ def attrs_on(attribute)
993
1068
  [:foo, :bar]
994
1069
  end
995
1070
  end
996
1071
 
997
1072
  describe SomeModel do
998
- it 'has 2 errors on name' do
999
- expect(subject).to have(2).errors_on(:name)
1073
+ it 'has 2 attributes on name' do
1074
+ expect(subject).to have(2).attrs_on(:name)
1000
1075
  end
1001
1076
  end
1002
1077
  END
@@ -1007,29 +1082,29 @@ module Transpec
1007
1082
  class SomeModel
1008
1083
  private
1009
1084
 
1010
- def errors_on(attribute)
1085
+ def attrs_on(attribute)
1011
1086
  [:foo, :bar]
1012
1087
  end
1013
1088
  end
1014
1089
 
1015
1090
  describe SomeModel do
1016
- it 'has 2 errors on name' do
1017
- expect(subject.send(:errors_on, :name).size).to eq(2)
1091
+ it 'has 2 attributes on name' do
1092
+ expect(subject.send(:attrs_on, :name).size).to eq(2)
1018
1093
  end
1019
1094
  end
1020
1095
  END
1021
1096
  end
1022
1097
 
1023
- it 'converts to `expect(obj.send(:errors_on, :name).size).to eq(2)` form' do
1098
+ it 'converts to `expect(obj.send(:attrs_on, :name).size).to eq(2)` form' do
1024
1099
  have_object.convert_to_standard_expectation!
1025
1100
  rewritten_source.should == expected_source
1026
1101
  end
1027
1102
 
1028
1103
  it 'adds record ' \
1029
- '`expect(obj).to have(n).errors_on(...)` -> `expect(obj.send(:errors_on, ...).size).to eq(n)`' do
1104
+ '`expect(obj).to have(n).attrs_on(...)` -> `expect(obj.send(:attrs_on, ...).size).to eq(n)`' do
1030
1105
  have_object.convert_to_standard_expectation!
1031
- record.original_syntax.should == 'expect(obj).to have(n).errors_on(...)'
1032
- record.converted_syntax.should == 'expect(obj.send(:errors_on, ...).size).to eq(n)'
1106
+ record.original_syntax.should == 'expect(obj).to have(n).attrs_on(...)'
1107
+ record.converted_syntax.should == 'expect(obj.send(:attrs_on, ...).size).to eq(n)'
1033
1108
  end
1034
1109
  end
1035
1110
  end
@@ -1038,14 +1113,14 @@ module Transpec
1038
1113
  let(:source) do
1039
1114
  <<-END
1040
1115
  class SomeModel
1041
- def errors_on(attribute)
1116
+ def attrs_on(attribute)
1042
1117
  [:foo, :bar]
1043
1118
  end
1044
1119
  end
1045
1120
 
1046
1121
  describe SomeModel do
1047
- it 'has 2 errors on name' do
1048
- expect(subject).to have(2).errors_on(:name)
1122
+ it 'has 2 attributes on name' do
1123
+ expect(subject).to have(2).attrs_on(:name)
1049
1124
  end
1050
1125
  end
1051
1126
  END
@@ -1054,29 +1129,29 @@ module Transpec
1054
1129
  let(:expected_source) do
1055
1130
  <<-END
1056
1131
  class SomeModel
1057
- def errors_on(attribute)
1132
+ def attrs_on(attribute)
1058
1133
  [:foo, :bar]
1059
1134
  end
1060
1135
  end
1061
1136
 
1062
1137
  describe SomeModel do
1063
- it 'has 2 errors on name' do
1064
- expect(subject.errors_on(:name).size).to eq(2)
1138
+ it 'has 2 attributes on name' do
1139
+ expect(subject.attrs_on(:name).size).to eq(2)
1065
1140
  end
1066
1141
  end
1067
1142
  END
1068
1143
  end
1069
1144
 
1070
- it 'converts to `expect(obj.errors_on(:name).size).to eq(2)` form' do
1145
+ it 'converts to `expect(obj.attrs_on(:name).size).to eq(2)` form' do
1071
1146
  have_object.convert_to_standard_expectation!
1072
1147
  rewritten_source.should == expected_source
1073
1148
  end
1074
1149
 
1075
1150
  it 'adds record ' \
1076
- '`expect(obj).to have(n).errors_on(...)` -> `expect(obj.errors_on(...).size).to eq(n)`' do
1151
+ '`expect(obj).to have(n).attrs_on(...)` -> `expect(obj.attrs_on(...).size).to eq(n)`' do
1077
1152
  have_object.convert_to_standard_expectation!
1078
- record.original_syntax.should == 'expect(obj).to have(n).errors_on(...)'
1079
- record.converted_syntax.should == 'expect(obj.errors_on(...).size).to eq(n)'
1153
+ record.original_syntax.should == 'expect(obj).to have(n).attrs_on(...)'
1154
+ record.converted_syntax.should == 'expect(obj.attrs_on(...).size).to eq(n)'
1080
1155
  end
1081
1156
  end
1082
1157
  end
@@ -63,6 +63,28 @@ module Transpec
63
63
  end
64
64
  end
65
65
 
66
+ context 'with expression `expect { }.should raise_error(SpecificErrorClass)`' do
67
+ let(:source) do
68
+ <<-END
69
+ describe 'example' do
70
+ it 'raises SpecificErrorClass' do
71
+ expect { do_something }.should raise_error(SpecificErrorClass)
72
+ end
73
+ end
74
+ END
75
+ end
76
+
77
+ let(:raise_error_object) { expect_object.raise_error_matcher }
78
+
79
+ it 'does nothing' do
80
+ rewritten_source.should == source
81
+ end
82
+
83
+ it 'reports nothing' do
84
+ raise_error_object.report.records.should be_empty
85
+ end
86
+ end
87
+
66
88
  context 'with expression `lambda { }.should raise_error(SpecificErrorClass) { |error| ... }`' do
67
89
  let(:source) do
68
90
  <<-END
@@ -399,7 +399,8 @@ module Transpec
399
399
  'lambda', 'Kernel.lambda', '::Kernel.lambda',
400
400
  'proc', 'Kernel.proc', '::Kernel.proc',
401
401
  'Proc.new', '::Proc.new',
402
- '->'
402
+ '->',
403
+ 'expect'
403
404
  ].each do |method|
404
405
  context "with expression `#{method} { ... }.should`" do
405
406
  let(:source) do
data/transpec.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
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'
29
- spec.add_runtime_dependency 'activesupport', '~> 4.0'
29
+ spec.add_runtime_dependency 'activesupport', '>= 3.0', '< 5.0'
30
30
 
31
31
  spec.add_development_dependency 'rake', '~> 10.1'
32
32
  spec.add_development_dependency 'rspec', '~> 2.14'
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: 2.0.0
4
+ version: 2.1.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: 2014-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -82,16 +82,22 @@ dependencies:
82
82
  name: activesupport
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - "~>"
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ - - "<"
86
89
  - !ruby/object:Gem::Version
87
- version: '4.0'
90
+ version: '5.0'
88
91
  type: :runtime
89
92
  prerelease: false
90
93
  version_requirements: !ruby/object:Gem::Requirement
91
94
  requirements:
92
- - - "~>"
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ - - "<"
93
99
  - !ruby/object:Gem::Version
94
- version: '4.0'
100
+ version: '5.0'
95
101
  - !ruby/object:Gem::Dependency
96
102
  name: rake
97
103
  requirement: !ruby/object:Gem::Requirement