shoulda-matchers 2.6.2 → 2.7.0

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +6 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +26 -22
  5. data/NEWS.md +52 -1
  6. data/README.md +8 -6
  7. data/Rakefile +1 -1
  8. data/doc_config/gh-pages/index.html.erb +1 -1
  9. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +1 -1
  10. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +26 -0
  11. data/features/rails_integration.feature +18 -3
  12. data/features/step_definitions/rails_steps.rb +21 -3
  13. data/gemfiles/3.0.gemfile +1 -1
  14. data/gemfiles/3.0.gemfile.lock +30 -24
  15. data/gemfiles/3.1.gemfile +1 -1
  16. data/gemfiles/3.1.gemfile.lock +32 -26
  17. data/gemfiles/3.1_1.9.2.gemfile +1 -1
  18. data/gemfiles/3.1_1.9.2.gemfile.lock +22 -19
  19. data/gemfiles/3.2.gemfile +1 -1
  20. data/gemfiles/3.2.gemfile.lock +32 -26
  21. data/gemfiles/3.2_1.9.2.gemfile +1 -1
  22. data/gemfiles/3.2_1.9.2.gemfile.lock +8 -8
  23. data/gemfiles/4.0.0.gemfile +2 -2
  24. data/gemfiles/4.0.0.gemfile.lock +35 -31
  25. data/gemfiles/4.0.1.gemfile +2 -2
  26. data/gemfiles/4.0.1.gemfile.lock +24 -22
  27. data/gemfiles/4.1.gemfile +1 -1
  28. data/gemfiles/4.1.gemfile.lock +26 -22
  29. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +10 -3
  30. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +24 -6
  31. data/lib/shoulda/matchers/active_model.rb +2 -2
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +1 -1
  33. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +1 -1
  34. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +5 -3
  35. data/lib/shoulda/matchers/active_model/{ensure_exclusion_of_matcher.rb → validate_exclusion_of_matcher.rb} +20 -10
  36. data/lib/shoulda/matchers/active_model/{ensure_inclusion_of_matcher.rb → validate_inclusion_of_matcher.rb} +52 -28
  37. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +28 -19
  38. data/lib/shoulda/matchers/active_record.rb +18 -16
  39. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -4
  40. data/lib/shoulda/matchers/active_record/association_matcher.rb +17 -12
  41. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +86 -0
  42. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +19 -0
  43. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +2 -1
  44. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +138 -0
  45. data/lib/shoulda/matchers/independent.rb +3 -2
  46. data/lib/shoulda/matchers/independent/{delegate_matcher.rb → delegate_method_matcher.rb} +69 -49
  47. data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +37 -0
  48. data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +15 -0
  49. data/lib/shoulda/matchers/version.rb +1 -1
  50. data/lib/shoulda/matchers/warn.rb +30 -2
  51. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +6 -0
  52. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +67 -5
  53. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -9
  54. data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +30 -3
  55. data/spec/shoulda/matchers/active_model/{ensure_exclusion_of_matcher_spec.rb → validate_exclusion_of_matcher_spec.rb} +29 -13
  56. data/spec/shoulda/matchers/active_model/{ensure_inclusion_of_matcher_spec.rb → validate_inclusion_of_matcher_spec.rb} +34 -16
  57. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +35 -0
  58. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +56 -1
  59. data/spec/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +101 -0
  60. data/spec/shoulda/matchers/doublespeak/object_double_spec.rb +6 -6
  61. data/spec/shoulda/matchers/independent/{delegate_matcher → delegate_method_matcher}/stubbed_target_spec.rb +1 -1
  62. data/spec/shoulda/matchers/independent/{delegate_matcher_spec.rb → delegate_method_matcher_spec.rb} +88 -29
  63. data/spec/spec_helper.rb +2 -3
  64. data/spec/support/fail_with_message_including_matcher.rb +14 -3
  65. data/spec/support/fail_with_message_matcher.rb +14 -2
  66. data/spec/support/rails_versions.rb +4 -0
  67. metadata +19 -14
  68. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ff48aa28034edc27f14e97808a24f0e777cf3ab
4
- data.tar.gz: 6432f92a9497036932281d941a437b40f5636e06
3
+ metadata.gz: e928b8bdcbb158173df075e2d49af0aeb4f584cc
4
+ data.tar.gz: 43b6015bf156cec9cb62f686a927e81eaea239b6
5
5
  SHA512:
6
- metadata.gz: 7f64a534e64d8f070d5e5d524bb9b21df80fa2afe93f4be3cf7b44e6ecb7a33fff7c91b87756194548fb0670548d0302467ce2d83e1371c42bf80f7283c1673b
7
- data.tar.gz: 940a2d667949ef94d42ada95554fda4a288af2d8cfa95f307900a3e345f46d867ca9cae347758e1f3bf2782e482397cc83a109aeb7359fbb3c69406f0abb0523
6
+ metadata.gz: 7a1d71a62c646c5607e59ace508393a28068e8c23c0744616a55f846b7bd2be2c7f31a2183c67f75ab72a7f51e03f8efc844ba9f22ad42817d5a17660c0cc0c2
7
+ data.tar.gz: f2834dcc2f6e3e052df77f725c676f55264e63ae6f6d20ac7c629728892ef4b0d515b2cedd75a00c1145d7d626d7ab1715eadcf20f0d8374adb446f69577822e
data/Appraisals CHANGED
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  rails_3 = proc do
9
9
  gem 'strong_parameters'
10
+ gem 'rspec-rails', '2.99.0'
10
11
  end
11
12
 
12
13
  rails_3_1 = proc do
@@ -17,6 +18,7 @@ rails_3_1 = proc do
17
18
  gem 'sass-rails', '~> 3.1.5'
18
19
  gem 'coffee-rails', '~> 3.1.1'
19
20
  gem 'uglifier', '>= 1.0.3'
21
+ gem 'rspec-rails', '2.99.0'
20
22
  end
21
23
 
22
24
  rails_3_2 = proc do
@@ -35,9 +37,9 @@ rails_4 = proc do
35
37
  gem 'coffee-rails', '~> 4.0.0'
36
38
  gem 'jquery-rails'
37
39
  gem 'turbolinks'
38
- gem 'jbuilder', '~> 1.2'
39
40
  gem 'sdoc'
40
41
  gem 'activeresource', '4.0.0'
42
+ gem 'rspec-rails', '~> 3.0.1'
41
43
  # Test suite makes heavy use of attr_accessible
42
44
  gem 'protected_attributes'
43
45
  end
@@ -78,6 +80,7 @@ if Gem::Requirement.new('> 1.9.2').satisfied_by?(ruby_version)
78
80
  appraise '4.0.0' do
79
81
  instance_eval(&rails_4)
80
82
  gem 'rails', '4.0.0'
83
+ gem 'jbuilder', '~> 1.2'
81
84
  gem 'sass-rails', '~> 4.0.0'
82
85
  gem 'bcrypt-ruby', '~> 3.0.0'
83
86
  end
@@ -85,8 +88,10 @@ if Gem::Requirement.new('> 1.9.2').satisfied_by?(ruby_version)
85
88
  appraise '4.0.1' do
86
89
  instance_eval(&rails_4)
87
90
  gem 'rails', '4.0.1'
91
+ gem 'jbuilder', '~> 1.2'
88
92
  gem 'sass-rails', '~> 4.0.0'
89
93
  gem 'bcrypt-ruby', '~> 3.1.2'
94
+ gem 'rspec-rails', '2.99.0'
90
95
  end
91
96
 
92
97
  appraise '4.1' do
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ gem 'cucumber', '~> 1.1'
10
10
  gem 'pry'
11
11
  gem 'rails', '~> 3.0'
12
12
  gem 'rake', '>= 0.9.2'
13
- gem 'rspec-rails', '>= 2.13.1', '< 3'
13
+ gem 'rspec-rails', '>= 2.99.0'
14
14
 
15
15
  # YARD
16
16
  gem 'yard'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shoulda-matchers (2.6.2)
4
+ shoulda-matchers (2.7.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -39,29 +39,29 @@ GEM
39
39
  rake
40
40
  thor (>= 0.14.0)
41
41
  arel (3.0.3)
42
- aruba (0.5.3)
43
- childprocess (~> 0.3.6)
42
+ aruba (0.6.0)
43
+ childprocess (>= 0.3.6)
44
44
  cucumber (>= 1.1.1)
45
45
  rspec-expectations (>= 2.7.0)
46
46
  bourne (1.5.0)
47
47
  mocha (>= 0.13.2, < 0.15)
48
48
  builder (3.0.4)
49
- childprocess (0.3.9)
49
+ childprocess (0.5.3)
50
50
  ffi (~> 1.0, >= 1.0.11)
51
51
  coderay (1.1.0)
52
- cucumber (1.3.10)
52
+ cucumber (1.3.16)
53
53
  builder (>= 2.1.2)
54
54
  diff-lcs (>= 1.1.3)
55
55
  gherkin (~> 2.12)
56
56
  multi_json (>= 1.7.5, < 2.0)
57
- multi_test (>= 0.0.2)
57
+ multi_test (>= 0.1.1)
58
58
  diff-lcs (1.2.5)
59
59
  erubis (2.7.0)
60
60
  ffi (1.9.3)
61
61
  gherkin (2.12.2)
62
62
  multi_json (~> 1.3)
63
63
  hike (1.2.3)
64
- i18n (0.6.9)
64
+ i18n (0.6.11)
65
65
  journey (1.0.4)
66
66
  json (1.8.1)
67
67
  mail (2.5.4)
@@ -72,8 +72,8 @@ GEM
72
72
  mime-types (1.25.1)
73
73
  mocha (0.14.0)
74
74
  metaclass (~> 0.0.1)
75
- multi_json (1.8.4)
76
- multi_test (0.0.3)
75
+ multi_json (1.10.1)
76
+ multi_test (0.1.1)
77
77
  polyglot (0.3.3)
78
78
  posix-spawn (0.3.8)
79
79
  pry (0.9.12.6)
@@ -86,7 +86,7 @@ GEM
86
86
  rack (1.4.5)
87
87
  rack-cache (1.2)
88
88
  rack (>= 0.4)
89
- rack-ssl (1.3.3)
89
+ rack-ssl (1.3.4)
90
90
  rack
91
91
  rack-test (0.6.2)
92
92
  rack (>= 1.0)
@@ -105,22 +105,26 @@ GEM
105
105
  rake (>= 0.8.7)
106
106
  rdoc (~> 3.4)
107
107
  thor (>= 0.14.6, < 2.0)
108
- rake (10.1.1)
108
+ rake (10.3.2)
109
109
  rdoc (3.12.2)
110
110
  json (~> 1.4)
111
111
  redcarpet (3.0.0)
112
- rspec-core (2.14.7)
113
- rspec-expectations (2.14.4)
114
- diff-lcs (>= 1.1.3, < 2.0)
115
- rspec-mocks (2.14.4)
116
- rspec-rails (2.14.1)
112
+ rspec-core (3.0.3)
113
+ rspec-support (~> 3.0.0)
114
+ rspec-expectations (3.0.3)
115
+ diff-lcs (>= 1.2.0, < 2.0)
116
+ rspec-support (~> 3.0.0)
117
+ rspec-mocks (3.0.3)
118
+ rspec-support (~> 3.0.0)
119
+ rspec-rails (3.0.2)
117
120
  actionpack (>= 3.0)
118
- activemodel (>= 3.0)
119
121
  activesupport (>= 3.0)
120
122
  railties (>= 3.0)
121
- rspec-core (~> 2.14.0)
122
- rspec-expectations (~> 2.14.0)
123
- rspec-mocks (~> 2.14.0)
123
+ rspec-core (~> 3.0.0)
124
+ rspec-expectations (~> 3.0.0)
125
+ rspec-mocks (~> 3.0.0)
126
+ rspec-support (~> 3.0.0)
127
+ rspec-support (3.0.3)
124
128
  shoulda-context (1.2.0)
125
129
  slop (3.4.7)
126
130
  sprockets (2.2.2)
@@ -129,7 +133,7 @@ GEM
129
133
  rack (~> 1.0)
130
134
  tilt (~> 1.1, != 1.3.0)
131
135
  sqlite3 (1.3.8)
132
- thor (0.18.1)
136
+ thor (0.19.1)
133
137
  tilt (1.4.1)
134
138
  treetop (1.4.15)
135
139
  polyglot
@@ -157,7 +161,7 @@ DEPENDENCIES
157
161
  rails (~> 3.0)
158
162
  rake (>= 0.9.2)
159
163
  redcarpet
160
- rspec-rails (>= 2.13.1, < 3)
164
+ rspec-rails (>= 2.99.0)
161
165
  shoulda-context (~> 1.2.0)
162
166
  shoulda-matchers!
163
167
  sqlite3
data/NEWS.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # HEAD
2
2
 
3
+ # 2.7.0
4
+
5
+ ### Deprecations
6
+
7
+ * `ensure_inclusion_of` has been renamed to `validate_inclusion_of`.
8
+ `ensure_inclusion_of` is deprecated and will be removed in 3.0.0.
9
+
10
+ * `ensure_exclusion_of` has been renamed to `validate_exclusion_of`.
11
+ `ensure_exclusion_of` is deprecated and will be removed in 3.0.0.
12
+
13
+ ### Bug fixes
14
+
15
+ * Fix `delegate_method` so that it does not raise an error if the method that
16
+ returns the delegate object is private.
17
+
18
+ * Warn when `ensure_inclusion_of` is chained with `.in_array([false, true])`
19
+ as well as with `.in_array([true, false])`.
20
+
21
+ * Fix `set_session` so that the `to` qualifier if given nil checks that the
22
+ session variable in question was set to nil (previously this actually did
23
+ nothing).
24
+
25
+ * Fix `filter_param` so that it works when `config.filter_parameters` contains
26
+ regexes.
27
+
28
+ * Fix `delegate_method` so that it can be required independent of Active
29
+ Support.
30
+
31
+ * Fix `validate_uniqueness_of`. When used against an unpersisted record whose
32
+ model contained a non-nullable column other than the one being validated, the
33
+ matcher would break. Even if the test set that column to a value beforehand,
34
+ the record had to be persisted in order for the matcher to work. Now this is
35
+ no longer the case and the record can remain unpersisted.
36
+
37
+ * Fix `validate_absence_of`: it required that a string be passed as the
38
+ attribute name rather than a symbol (which is the usual and documented usage).
39
+
40
+ ### Improvements
41
+
42
+ * `have_and_belongs_to_many` now checks to make sure that the join table
43
+ contains the correct columns for the left- and right-hand side of the
44
+ association.
45
+
46
+ * Reword failure message for `delegate_method` so that it's a little more
47
+ helpful.
48
+
49
+ ### Features
50
+
51
+ * Add new matcher `define_enum_for` to test usage of the `enum` macro introduced
52
+ in Rails 4.1.
53
+
3
54
  # 2.6.2
4
55
 
5
56
  ### Bug fixes
@@ -102,7 +153,7 @@
102
153
  * Change `validate_uniqueness_of(...)` so that it provides default values for
103
154
  non-nullable attributes.
104
155
 
105
- * Running `rake` now installs Appraisals before running the test suite.
156
+ * Running `rake` now installs Appraisals before running the test suite.
106
157
  (Additionally, we now manage Appraisals using the `appraisal` executable in
107
158
  Appraisal 1.0.0.)
108
159
 
data/README.md CHANGED
@@ -12,10 +12,10 @@ complex, and error-prone.
12
12
  tests usage of Rails 3's `attr_accessible` and `attr_protected` macros.
13
13
  * **[allow_value](lib/shoulda/matchers/active_model/allow_value_matcher.rb)** tests usage of
14
14
  the `validates_format_of` validation.
15
- * **[ensure_inclusion_of](lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb)** tests
16
- usage of `validates_inclusion_of`.
17
- * **[ensure_exclusion_of](lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb)** tests
18
- usage of `validates_exclusion_of`.
15
+ * **[validate_inclusion_of](lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb)**
16
+ tests usage of `validates_inclusion_of`.
17
+ * **[validate_exclusion_of](lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb)**
18
+ tests usage of `validates_exclusion_of`.
19
19
  * **[ensure_length_of](lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb)** tests usage
20
20
  of `validates_length_of`.
21
21
  * **[have_secure_password](lib/shoulda/matchers/active_model/have_secure_password_matcher.rb)** tests
@@ -35,6 +35,8 @@ complex, and error-prone.
35
35
  tests usage of the `accepts_nested_attributes_for` macro.
36
36
  * **[belong_to](lib/shoulda/matchers/active_record/association_matcher.rb)** tests
37
37
  your `belongs_to` associations.
38
+ * **[define_enum_for](lib/shoulda/matchers/active_record/define_enum_for_matcher.rb)**
39
+ tests usage of the `enum` macro.
38
40
  * **[have_many](lib/shoulda/matchers/active_record/association_matcher.rb)** tests
39
41
  your `has_many` associations.
40
42
  * **[have_one](lib/shoulda/matchers/active_record/association_matcher.rb)** tests your
@@ -72,7 +74,7 @@ complex, and error-prone.
72
74
 
73
75
  ### Independent Matchers
74
76
 
75
- * **[delegate_matcher](lib/shoulda/matchers/independent/delegate_matcher.rb)**
77
+ * **[delegate_method](lib/shoulda/matchers/independent/delegate_matcher.rb)**
76
78
  tests that an object forwards messages to other, internal objects by way of
77
79
  delegation.
78
80
 
@@ -170,6 +172,6 @@ and may be redistributed under the terms specified in the
170
172
  [fury]: http://badge.fury.io/rb/shoulda-matchers
171
173
  [travis-badge]: https://secure.travis-ci.org/thoughtbot/shoulda-matchers.png?branch=master
172
174
  [travis]: http://travis-ci.org/thoughtbot/shoulda-matchers
173
- [rubydocs]: http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames
175
+ [rubydocs]: http://thoughtbot.github.io/shoulda-matchers
174
176
  [community]: http://thoughtbot.com/community
175
177
  [contributors]: https://github.com/thoughtbot/shoulda-matchers/contributors
data/Rakefile CHANGED
@@ -96,7 +96,7 @@ namespace :docs do
96
96
  rewrite_index_to_inject_version(ref, version)
97
97
 
98
98
  within_gh_pages do
99
- sh "git add --ignore-removal #{ref}"
99
+ sh "git add #{ref}"
100
100
  end
101
101
 
102
102
  if options[:latest_version]
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>shoulda-matchers Documentation - latest</title>
5
- <meta http-equiv="refresh" content="0;URL=http://mcmire.github.io/shoulda-matchers/<%= locals[:ref] %>">
5
+ <meta http-equiv="refresh" content="0;URL=http://thoughtbot.github.io/shoulda-matchers/<%= locals[:ref] %>">
6
6
  </head>
7
7
  <body>
8
8
  </body>
@@ -1,4 +1,4 @@
1
- @import "http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,600,600italic,800|Droid+Sans+Mono";
1
+ @import "http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic,600,600italic,800|Droid+Sans+Mono";
2
2
 
3
3
  body {
4
4
  font-size: 16px;
@@ -209,6 +209,10 @@ h4 + h5 {
209
209
 
210
210
  /* Class/Module */
211
211
 
212
+ .summary .deprecated {
213
+ display: none;
214
+ }
215
+
212
216
  .method_details {}
213
217
  .method_details td {
214
218
  padding: 10px;
@@ -253,6 +257,28 @@ h4 + h5 {
253
257
  color: #93a1a1 /* Comment */
254
258
  }
255
259
 
260
+ .method_details .deprecated {
261
+ margin-bottom: 1em;
262
+ font-size: 1.1em;
263
+ }
264
+
265
+ .method_details .deprecated strong {
266
+ background-color: #F03434;
267
+ color: white;
268
+ text-transform: uppercase;
269
+ border-radius: 3px;
270
+ padding: 0 4px;
271
+ }
272
+
273
+ .method_details .deprecated .inline {
274
+ padding-left: 3px;
275
+ }
276
+
277
+ .method_details .deprecated div,
278
+ .method_details .deprecated p {
279
+ display: inline
280
+ }
281
+
256
282
  .docstring, .method_details .showSource, .method_details .source_code {
257
283
  margin-left: 1em;
258
284
  }
@@ -66,6 +66,9 @@ Feature: integrate with Rails
66
66
  And I write to "spec/models/user_spec.rb" with:
67
67
  """
68
68
  require 'spec_helper'
69
+ if RSpec::Core::Version::STRING.to_i >= 3
70
+ require 'rails_helper'
71
+ end
69
72
 
70
73
  describe User do
71
74
  it { should validate_presence_of(:name) }
@@ -74,13 +77,16 @@ Feature: integrate with Rails
74
77
  When I write to "spec/controllers/examples_controller_spec.rb" with:
75
78
  """
76
79
  require 'spec_helper'
80
+ if RSpec::Core::Version::STRING.to_i >= 3
81
+ require 'rails_helper'
82
+ end
77
83
 
78
84
  describe ExamplesController, "show" do
79
85
  before { get :show }
80
86
  it { should respond_with(:success) }
81
87
  end
82
88
  """
83
- When I successfully run `bundle exec rake spec SPEC_OPTS=-fs --trace`
89
+ When I successfully run `bundle exec rake spec SPEC_OPTS=-fd --trace`
84
90
  Then the output should contain "2 examples, 0 failures"
85
91
  And the output should contain "should require name to be set"
86
92
  And the output should contain "should respond with 200"
@@ -96,6 +102,9 @@ Feature: integrate with Rails
96
102
  And I write to "spec/models/user_spec.rb" with:
97
103
  """
98
104
  require 'spec_helper'
105
+ if RSpec::Core::Version::STRING.to_i >= 3
106
+ require 'rails_helper'
107
+ end
99
108
 
100
109
  describe User do
101
110
  it { should validate_presence_of(:name) }
@@ -104,6 +113,9 @@ Feature: integrate with Rails
104
113
  When I write to "spec/controllers/examples_controller_spec.rb" with:
105
114
  """
106
115
  require 'spec_helper'
116
+ if RSpec::Core::Version::STRING.to_i >= 3
117
+ require 'rails_helper'
118
+ end
107
119
 
108
120
  describe ExamplesController, "show" do
109
121
  before { get :show }
@@ -112,7 +124,7 @@ Feature: integrate with Rails
112
124
  end
113
125
  """
114
126
  When I run `bundle exec spring stop`
115
- When I successfully run `bundle exec spring rspec spec -fs`
127
+ When I successfully run `bundle exec spring rspec spec -fd`
116
128
  Then the output should contain "3 examples, 0 failures"
117
129
  And the output should contain "should require name to be set"
118
130
  And the output should contain "should respond with 200"
@@ -124,6 +136,9 @@ Feature: integrate with Rails
124
136
  And I write to "spec/models/user_spec.rb" with:
125
137
  """
126
138
  require 'spec_helper'
139
+ if RSpec::Core::Version::STRING.to_i == 3
140
+ require 'rails_helper'
141
+ end
127
142
 
128
143
  describe User do
129
144
  it { should validate_presence_of(:name) }
@@ -140,6 +155,6 @@ Feature: integrate with Rails
140
155
  end
141
156
  end
142
157
  """
143
- When I successfully run `bundle exec rake spec test:functionals SPEC_OPTS=-fs --trace`
158
+ When I successfully run `bundle exec rake spec test:functionals SPEC_OPTS=-fd --trace`
144
159
  Then the output should contain "1 example, 0 failures"
145
160
  Then the output should indicate that 1 test was run
@@ -70,14 +70,16 @@ When 'I run the rspec generator' do
70
70
  end
71
71
 
72
72
  When 'I configure the application to use rspec-rails' do
73
- append_to_gemfile %q(gem 'rspec-rails', '~> 2.13')
73
+ append_to_gemfile <<-GEMFILE
74
+ gem 'rspec-rails', '#{rspec_rails_version}'
75
+ GEMFILE
74
76
  steps %{And I install gems}
75
77
  end
76
78
 
77
79
  When 'I configure the application to use rspec-rails in test and development' do
78
80
  append_to_gemfile <<-GEMFILE
79
81
  group :test, :development do
80
- gem 'rspec-rails', '~> 2.13'
82
+ gem 'rspec-rails', '#{rspec_rails_version}'
81
83
  end
82
84
  GEMFILE
83
85
  steps %{And I install gems}
@@ -90,7 +92,7 @@ When 'I configure the application to use shoulda-context' do
90
92
  end
91
93
 
92
94
  When 'I require shoulda-matchers following rspec-rails' do
93
- insert_line_after 'spec/spec_helper.rb',
95
+ insert_line_after test_helper_path,
94
96
  "require 'rspec/rails'",
95
97
  "require 'shoulda/matchers'"
96
98
  end
@@ -204,6 +206,22 @@ module FileHelpers
204
206
  def rails_lt_4?
205
207
  Gem::Requirement.new('< 4').satisfied_by?(rails_version)
206
208
  end
209
+
210
+ def rspec_rails_version
211
+ Bundler.definition.specs['rspec-rails'][0].version
212
+ end
213
+
214
+ def rspec_rails_gte_3?
215
+ Gem::Requirement.new('>= 3').satisfied_by?(rspec_rails_version)
216
+ end
217
+
218
+ def test_helper_path
219
+ if rspec_rails_gte_3?
220
+ 'spec/rails_helper.rb'
221
+ else
222
+ 'spec/spec_helper.rb'
223
+ end
224
+ end
207
225
  end
208
226
 
209
227
  World(FileHelpers)