rspec-rails 3.0.2 → 3.1.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 (42) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +17 -0
  5. data/README.md +7 -7
  6. data/lib/generators/rspec.rb +10 -6
  7. data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
  8. data/lib/generators/rspec/install/install_generator.rb +19 -2
  9. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +13 -4
  10. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  11. data/lib/generators/rspec/job/job_generator.rb +12 -0
  12. data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  13. data/lib/generators/rspec/model/model_generator.rb +18 -5
  14. data/lib/generators/rspec/scaffold/scaffold_generator.rb +107 -100
  15. data/lib/rspec-rails.rb +1 -1
  16. data/lib/rspec/rails.rb +1 -0
  17. data/lib/rspec/rails/adapters.rb +9 -7
  18. data/lib/rspec/rails/configuration.rb +2 -3
  19. data/lib/rspec/rails/example/controller_example_group.rb +172 -149
  20. data/lib/rspec/rails/example/feature_example_group.rb +25 -23
  21. data/lib/rspec/rails/example/helper_example_group.rb +27 -25
  22. data/lib/rspec/rails/example/mailer_example_group.rb +26 -22
  23. data/lib/rspec/rails/example/model_example_group.rb +8 -6
  24. data/lib/rspec/rails/example/request_example_group.rb +19 -17
  25. data/lib/rspec/rails/example/routing_example_group.rb +40 -38
  26. data/lib/rspec/rails/example/view_example_group.rb +140 -137
  27. data/lib/rspec/rails/extensions/active_record/proxy.rb +0 -1
  28. data/lib/rspec/rails/feature_check.rb +35 -0
  29. data/lib/rspec/rails/fixture_support.rb +1 -1
  30. data/lib/rspec/rails/matchers.rb +5 -2
  31. data/lib/rspec/rails/matchers/be_a_new.rb +68 -64
  32. data/lib/rspec/rails/matchers/be_new_record.rb +24 -20
  33. data/lib/rspec/rails/matchers/be_valid.rb +38 -34
  34. data/lib/rspec/rails/matchers/have_http_status.rb +340 -334
  35. data/lib/rspec/rails/matchers/have_rendered.rb +35 -32
  36. data/lib/rspec/rails/matchers/redirect_to.rb +30 -27
  37. data/lib/rspec/rails/matchers/routing_matchers.rb +103 -101
  38. data/lib/rspec/rails/version.rb +1 -1
  39. data/lib/rspec/rails/view_assigns.rb +1 -2
  40. data/lib/rspec/rails/view_rendering.rb +6 -8
  41. metadata +16 -13
  42. metadata.gz.sig +3 -2
@@ -1,41 +1,44 @@
1
- module RSpec::Rails::Matchers
2
- # Matcher for template rendering.
3
- module RenderTemplate
4
- # @private
5
- class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
1
+ module RSpec
2
+ module Rails
3
+ module Matchers
4
+ # Matcher for template rendering.
5
+ module RenderTemplate
6
+ # @private
7
+ class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
8
+ def initialize(scope, expected, message = nil)
9
+ @expected = Symbol === expected ? expected.to_s : expected
10
+ @message = message
11
+ @scope = scope
12
+ end
6
13
 
7
- def initialize(scope, expected, message=nil)
8
- @expected = Symbol === expected ? expected.to_s : expected
9
- @message = message
10
- @scope = scope
11
- end
14
+ # @api private
15
+ def matches?(*)
16
+ match_unless_raises ActiveSupport::TestCase::Assertion do
17
+ @scope.assert_template expected, @message
18
+ end
19
+ end
20
+
21
+ # @api private
22
+ def failure_message
23
+ rescued_exception.message
24
+ end
12
25
 
13
- # @api private
14
- def matches?(*)
15
- match_unless_raises ActiveSupport::TestCase::Assertion do
16
- @scope.assert_template expected, @message
26
+ # @api private
27
+ def failure_message_when_negated
28
+ "expected not to render #{expected.inspect}, but did"
29
+ end
17
30
  end
18
- end
19
31
 
20
- # @api private
21
- def failure_message
22
- rescued_exception.message
23
- end
32
+ # Delegates to `assert_template`.
33
+ #
34
+ # @example
35
+ # expect(response).to have_rendered("new")
36
+ def have_rendered(options, message = nil)
37
+ RenderTemplateMatcher.new(self, options, message)
38
+ end
24
39
 
25
- # @api private
26
- def failure_message_when_negated
27
- "expected not to render #{expected.inspect}, but did"
40
+ alias_method :render_template, :have_rendered
28
41
  end
29
42
  end
30
-
31
- # Delegates to `assert_template`.
32
- #
33
- # @example
34
- # expect(response).to have_rendered("new")
35
- def have_rendered(options, message=nil)
36
- RenderTemplateMatcher.new(self, options, message)
37
- end
38
-
39
- alias_method :render_template, :have_rendered
40
43
  end
41
44
  end
@@ -1,35 +1,38 @@
1
- module RSpec::Rails::Matchers
2
- # Matcher for redirects.
3
- module RedirectTo
4
- # @private
5
- class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher
1
+ module RSpec
2
+ module Rails
3
+ module Matchers
4
+ # Matcher for redirects.
5
+ module RedirectTo
6
+ # @private
7
+ class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher
8
+ def initialize(scope, expected)
9
+ @expected = expected
10
+ @scope = scope
11
+ end
6
12
 
7
- def initialize(scope, expected)
8
- @expected = expected
9
- @scope = scope
10
- end
13
+ def matches?(_)
14
+ match_unless_raises ActiveSupport::TestCase::Assertion do
15
+ @scope.assert_redirected_to(@expected)
16
+ end
17
+ end
11
18
 
12
- def matches?(_)
13
- match_unless_raises ActiveSupport::TestCase::Assertion do
14
- @scope.assert_redirected_to(@expected)
15
- end
16
- end
19
+ def failure_message
20
+ rescued_exception.message
21
+ end
17
22
 
18
- def failure_message
19
- rescued_exception.message
20
- end
23
+ def failure_message_when_negated
24
+ "expected not to redirect to #{@expected.inspect}, but did"
25
+ end
26
+ end
21
27
 
22
- def failure_message_when_negated
23
- "expected not to redirect to #{@expected.inspect}, but did"
28
+ # Delegates to `assert_redirected_to`.
29
+ #
30
+ # @example
31
+ # expect(response).to redirect_to(:action => "new")
32
+ def redirect_to(target)
33
+ RedirectTo.new(self, target)
34
+ end
24
35
  end
25
36
  end
26
-
27
- # Delegates to `assert_redirected_to`.
28
- #
29
- # @example
30
- # expect(response).to redirect_to(:action => "new")
31
- def redirect_to(target)
32
- RedirectTo.new(self, target)
33
- end
34
37
  end
35
38
  end
@@ -1,117 +1,119 @@
1
- module RSpec::Rails::Matchers
2
- # Matchers to help with specs for routing code.
3
- module RoutingMatchers
4
- extend RSpec::Matchers::DSL
1
+ module RSpec
2
+ module Rails
3
+ module Matchers
4
+ # Matchers to help with specs for routing code.
5
+ module RoutingMatchers
6
+ extend RSpec::Matchers::DSL
5
7
 
6
- # @private
7
- class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
8
+ # @private
9
+ class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
10
+ def initialize(scope, *expected)
11
+ @scope = scope
12
+ @expected = expected[1] || {}
13
+ if Hash === expected[0]
14
+ @expected.merge!(expected[0])
15
+ else
16
+ controller, action = expected[0].split('#')
17
+ @expected.merge!(:controller => controller, :action => action)
18
+ end
19
+ end
8
20
 
9
- def initialize(scope, *expected)
10
- @scope = scope
11
- @expected = expected[1] || {}
12
- if Hash === expected[0]
13
- @expected.merge!(expected[0])
14
- else
15
- controller, action = expected[0].split('#')
16
- @expected.merge!(:controller => controller, :action => action)
17
- end
18
- end
21
+ def matches?(verb_to_path_map)
22
+ @actual = @verb_to_path_map = verb_to_path_map
23
+ # assert_recognizes does not consider ActionController::RoutingError an
24
+ # assertion failure, so we have to capture that and Assertion here.
25
+ match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
26
+ path, query = *verb_to_path_map.values.first.split('?')
27
+ @scope.assert_recognizes(
28
+ @expected,
29
+ { :method => verb_to_path_map.keys.first, :path => path },
30
+ Rack::Utils.parse_nested_query(query)
31
+ )
32
+ end
33
+ end
19
34
 
20
- def matches?(verb_to_path_map)
21
- @actual = @verb_to_path_map = verb_to_path_map
22
- # assert_recognizes does not consider ActionController::RoutingError an
23
- # assertion failure, so we have to capture that and Assertion here.
24
- match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
25
- path, query = *verb_to_path_map.values.first.split('?')
26
- @scope.assert_recognizes(
27
- @expected,
28
- {:method => verb_to_path_map.keys.first, :path => path},
29
- Rack::Utils::parse_nested_query(query)
30
- )
31
- end
32
- end
35
+ def failure_message
36
+ rescued_exception.message
37
+ end
33
38
 
34
- def failure_message
35
- rescued_exception.message
36
- end
39
+ def failure_message_when_negated
40
+ "expected #{@actual.inspect} not to route to #{@expected.inspect}"
41
+ end
37
42
 
38
- def failure_message_when_negated
39
- "expected #{@actual.inspect} not to route to #{@expected.inspect}"
40
- end
43
+ def description
44
+ "route #{@actual.inspect} to #{@expected.inspect}"
45
+ end
46
+ end
41
47
 
42
- def description
43
- "route #{@actual.inspect} to #{@expected.inspect}"
44
- end
45
- end
48
+ # Delegates to `assert_recognizes`. Supports short-hand controller/action
49
+ # declarations (e.g. `"controller#action"`).
50
+ #
51
+ # @example
52
+ #
53
+ # expect(:get => "/things/special").to route_to(
54
+ # :controller => "things",
55
+ # :action => "special"
56
+ # )
57
+ #
58
+ # expect(:get => "/things/special").to route_to("things#special")
59
+ #
60
+ # @see http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
61
+ def route_to(*expected)
62
+ RouteToMatcher.new(self, *expected)
63
+ end
46
64
 
47
- # Delegates to `assert_recognizes`. Supports short-hand controller/action
48
- # declarations (e.g. `"controller#action"`).
49
- #
50
- # @example
51
- #
52
- # expect(:get => "/things/special").to route_to(
53
- # :controller => "things",
54
- # :action => "special"
55
- # )
56
- #
57
- # expect(:get => "/things/special").to route_to("things#special")
58
- #
59
- # @see http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
60
- def route_to(*expected)
61
- RouteToMatcher.new(self, *expected)
62
- end
65
+ # @private
66
+ class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
67
+ def initialize(scope)
68
+ @scope = scope
69
+ end
63
70
 
64
- # @private
65
- class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
71
+ def matches?(path)
72
+ @actual = path
73
+ match_unless_raises ActionController::RoutingError do
74
+ @routing_options = @scope.routes.recognize_path(
75
+ path.values.first, :method => path.keys.first
76
+ )
77
+ end
78
+ end
66
79
 
67
- def initialize(scope)
68
- @scope = scope
69
- end
80
+ def failure_message
81
+ "expected #{@actual.inspect} to be routable"
82
+ end
70
83
 
71
- def matches?(path)
72
- @actual = path
73
- match_unless_raises ActionController::RoutingError do
74
- @routing_options = @scope.routes.recognize_path(
75
- path.values.first, :method => path.keys.first
76
- )
84
+ def failure_message_when_negated
85
+ "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
86
+ end
77
87
  end
78
- end
79
-
80
- def failure_message
81
- "expected #{@actual.inspect} to be routable"
82
- end
83
88
 
84
- def failure_message_when_negated
85
- "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
86
- end
87
- end
88
-
89
- # Passes if the route expression is recognized by the Rails router based on
90
- # the declarations in `config/routes.rb`. Delegates to
91
- # `RouteSet#recognize_path`.
92
- #
93
- # @example You can use route helpers provided by rspec-rails.
94
- # expect(:get => "/a/path").to be_routable
95
- # expect(:post => "/another/path").to be_routable
96
- # expect(:put => "/yet/another/path").to be_routable
97
- def be_routable
98
- BeRoutableMatcher.new(self)
99
- end
89
+ # Passes if the route expression is recognized by the Rails router based on
90
+ # the declarations in `config/routes.rb`. Delegates to
91
+ # `RouteSet#recognize_path`.
92
+ #
93
+ # @example You can use route helpers provided by rspec-rails.
94
+ # expect(:get => "/a/path").to be_routable
95
+ # expect(:post => "/another/path").to be_routable
96
+ # expect(:put => "/yet/another/path").to be_routable
97
+ def be_routable
98
+ BeRoutableMatcher.new(self)
99
+ end
100
100
 
101
- # Helpers for matching different route types.
102
- module RouteHelpers
103
- # @!method get
104
- # @!method post
105
- # @!method put
106
- # @!method patch
107
- # @!method delete
108
- # @!method options
109
- # @!method head
110
- #
111
- # Shorthand method for matching this type of route.
112
- %w(get post put patch delete options head).each do |method|
113
- define_method method do |path|
114
- { method.to_sym => path }
101
+ # Helpers for matching different route types.
102
+ module RouteHelpers
103
+ # @!method get
104
+ # @!method post
105
+ # @!method put
106
+ # @!method patch
107
+ # @!method delete
108
+ # @!method options
109
+ # @!method head
110
+ #
111
+ # Shorthand method for matching this type of route.
112
+ %w[get post put patch delete options head].each do |method|
113
+ define_method method do |path|
114
+ { method.to_sym => path }
115
+ end
116
+ end
115
117
  end
116
118
  end
117
119
  end
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec Rails.
4
4
  module Version
5
5
  # Current version of RSpec Rails, in semantic versioning format.
6
- STRING = '3.0.2'
6
+ STRING = '3.1.0'
7
7
  end
8
8
  end
9
9
  end
@@ -35,12 +35,11 @@ module RSpec
35
35
  super.merge(_encapsulated_assigns)
36
36
  end
37
37
 
38
- private
38
+ private
39
39
 
40
40
  def _encapsulated_assigns
41
41
  @_encapsulated_assigns ||= {}
42
42
  end
43
-
44
43
  end
45
44
  end
46
45
  end
@@ -11,7 +11,7 @@ module RSpec
11
11
  # DSL methods
12
12
  module ClassMethods
13
13
  # @see RSpec::Rails::ControllerExampleGroup
14
- def render_views(true_or_false=true)
14
+ def render_views(true_or_false = true)
15
15
  @render_views = true_or_false
16
16
  end
17
17
 
@@ -44,15 +44,13 @@ module RSpec
44
44
  end
45
45
 
46
46
  def find_all(*args)
47
- original_path_set.find_all(*args).collect do |template|
47
+ original_path_set.find_all(*args).map do |template|
48
48
  ::ActionView::Template.new(
49
49
  "",
50
50
  template.identifier,
51
51
  EmptyTemplateHandler,
52
- {
53
- :virtual_path => template.virtual_path,
54
- :format => template.formats
55
- }
52
+ :virtual_path => template.virtual_path,
53
+ :format => template.formats
56
54
  )
57
55
  end
58
56
  end
@@ -60,7 +58,7 @@ module RSpec
60
58
 
61
59
  # @private
62
60
  class EmptyTemplateHandler
63
- def self.call(template)
61
+ def self.call(_template)
64
62
  %("")
65
63
  end
66
64
  end
@@ -77,7 +75,7 @@ module RSpec
77
75
  lookup_context.view_paths.push(*_path_decorator(new_path))
78
76
  end
79
77
 
80
- private
78
+ private
81
79
 
82
80
  def _path_decorator(path)
83
81
  EmptyTemplatePathSetDecorator.new(ActionView::PathSet.new(Array.wrap(path)))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
@@ -32,7 +32,7 @@ cert_chain:
32
32
  1yHC1AcSYpvi2dAbOiHT5iQF+krm4wse8KctXgTNnjMsHEoGKulJS2/sZl90jcCz
33
33
  muA=
34
34
  -----END CERTIFICATE-----
35
- date: 2014-07-21 00:00:00.000000000 Z
35
+ date: 2014-09-05 00:00:00.000000000 Z
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: activesupport
@@ -82,56 +82,56 @@ dependencies:
82
82
  requirements:
83
83
  - - "~>"
84
84
  - !ruby/object:Gem::Version
85
- version: 3.0.0
85
+ version: 3.1.0
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - "~>"
91
91
  - !ruby/object:Gem::Version
92
- version: 3.0.0
92
+ version: 3.1.0
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rspec-expectations
95
95
  requirement: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: 3.0.0
99
+ version: 3.1.0
100
100
  type: :runtime
101
101
  prerelease: false
102
102
  version_requirements: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: 3.0.0
106
+ version: 3.1.0
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: rspec-mocks
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: 3.0.0
113
+ version: 3.1.0
114
114
  type: :runtime
115
115
  prerelease: false
116
116
  version_requirements: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: 3.0.0
120
+ version: 3.1.0
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: rspec-support
123
123
  requirement: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - "~>"
126
126
  - !ruby/object:Gem::Version
127
- version: 3.0.0
127
+ version: 3.1.0
128
128
  type: :runtime
129
129
  prerelease: false
130
130
  version_requirements: !ruby/object:Gem::Requirement
131
131
  requirements:
132
132
  - - "~>"
133
133
  - !ruby/object:Gem::Version
134
- version: 3.0.0
134
+ version: 3.1.0
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rake
137
137
  requirement: !ruby/object:Gem::Requirement
@@ -180,14 +180,14 @@ dependencies:
180
180
  requirements:
181
181
  - - '='
182
182
  - !ruby/object:Gem::Version
183
- version: 1.0.0
183
+ version: 1.1.2
184
184
  type: :development
185
185
  prerelease: false
186
186
  version_requirements: !ruby/object:Gem::Requirement
187
187
  requirements:
188
188
  - - '='
189
189
  - !ruby/object:Gem::Version
190
- version: 1.0.0
190
+ version: 1.1.2
191
191
  description: RSpec for Rails
192
192
  email: rspec@googlegroups.com
193
193
  executables: []
@@ -212,6 +212,8 @@ files:
212
212
  - lib/generators/rspec/install/templates/spec/rails_helper.rb
213
213
  - lib/generators/rspec/integration/integration_generator.rb
214
214
  - lib/generators/rspec/integration/templates/request_spec.rb
215
+ - lib/generators/rspec/job/job_generator.rb
216
+ - lib/generators/rspec/job/templates/job_spec.rb.erb
215
217
  - lib/generators/rspec/mailer/mailer_generator.rb
216
218
  - lib/generators/rspec/mailer/templates/fixture
217
219
  - lib/generators/rspec/mailer/templates/mailer_spec.rb
@@ -245,6 +247,7 @@ files:
245
247
  - lib/rspec/rails/example/view_example_group.rb
246
248
  - lib/rspec/rails/extensions.rb
247
249
  - lib/rspec/rails/extensions/active_record/proxy.rb
250
+ - lib/rspec/rails/feature_check.rb
248
251
  - lib/rspec/rails/fixture_support.rb
249
252
  - lib/rspec/rails/matchers.rb
250
253
  - lib/rspec/rails/matchers/be_a_new.rb
@@ -284,6 +287,6 @@ rubyforge_project: rspec
284
287
  rubygems_version: 2.2.2
285
288
  signing_key:
286
289
  specification_version: 4
287
- summary: rspec-rails-3.0.2
290
+ summary: rspec-rails-3.1.0
288
291
  test_files: []
289
292
  has_rdoc: