rspec-rails 2.10.1 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md CHANGED
@@ -1,3 +1,19 @@
1
+ ### 2.11.0 / 2012-07-07
2
+ [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...v2.11.0)
3
+
4
+ Enhancements
5
+
6
+ * The generated `spec/spec_helper.rb` sets `config.order = "random"` so that
7
+ specs run in random order by default.
8
+ * rename `render_template` to `have_rendered` (and alias to `render_template`
9
+ for backward compatibility)
10
+
11
+ Bug fixes
12
+
13
+ * "uninitialized constant" errors are avoided when using using gems like
14
+ `rspec-rails-uncommitted` that define `Rspec::Rails` before `rspec-rails`
15
+ loads (Andy Lindeman)
16
+
1
17
  ### 2.10.1 / 2012-05-03
2
18
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.0...v2.10.1)
3
19
 
@@ -5,6 +21,8 @@ Bug fixes
5
21
 
6
22
  * fix regression introduced in 2.10.0 that broke integration with Devise
7
23
  (https://github.com/rspec/rspec-rails/issues/534)
24
+ * remove generation of helper specs when running the scaffold generator, as
25
+ Rails already does this (Jack Dempsey)
8
26
 
9
27
  ### 2.10.0 / 2012-05-03
10
28
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.9.0...v2.10.0)
@@ -24,7 +42,7 @@ Bug fixes
24
42
  ### 2.9.0 / 2012-03-17
25
43
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.8.1...v2.9.0)
26
44
 
27
- Enhancments
45
+ Enhancements
28
46
 
29
47
  * add description method to RouteToMatcher (John Wulff)
30
48
  * Run "db:test:clone_structure" instead of "db:test:prepare" if Active Record's
@@ -90,7 +108,7 @@ you'll have to upgrade to rspec-rails-2.8.1 when you upgrade to rails >=
90
108
 
91
109
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.6.1...v2.7.0)
92
110
 
93
- * Enhancments
111
+ * Enhancements
94
112
  * `ActiveRecord::Relation` can use the `=~` matcher (Andy Lindeman)
95
113
  * Make generated controller spec more consistent with regard to ids
96
114
  (Brent J. Nordquist)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rspec-rails-2
1
+ # rspec-rails-2 [![Build Status](https://secure.travis-ci.org/rspec/rspec-rails.png?branch=master)](http://travis-ci.org/rspec/rspec-rails) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails)
2
2
 
3
3
  rspec-2 for rails-3 with lightweight extensions to each
4
4
 
@@ -130,7 +130,7 @@ users like to use extension libraries like FactoryGirl and Capybara:
130
130
  ```ruby
131
131
  describe "home page" do
132
132
  it "displays the user's username after successful login" do
133
- user = Factory(:user, :username => "jdoe", :password => "secret")
133
+ user = FactoryGirl.create(:user, :username => "jdoe", :password => "secret")
134
134
  visit "/login"
135
135
  fill_in "Username", :with => "jdoe"
136
136
  fill_in "Password", :with => "secret"
@@ -181,7 +181,7 @@ end
181
181
  describe WidgetsController do
182
182
  describe "GET index" do
183
183
  it "assigns all widgets to @widgets" do
184
- widget = Factory(:widget)
184
+ widget = FactoryGirl.create(:widget)
185
185
  get :index
186
186
  assigns(:widgets).should eq([widget])
187
187
  end
@@ -71,7 +71,7 @@ Feature: render_views
71
71
  end
72
72
  end
73
73
  """
74
- When I run `rspec spec --format documentation`
74
+ When I run `rspec spec --order default --format documentation`
75
75
  Then the output should contain:
76
76
  """
77
77
  WidgetsController
@@ -1,5 +1,5 @@
1
1
  Feature: helper spec
2
-
2
+
3
3
  Helper specs live in `spec/helpers`, or any example group with `:type =>
4
4
  :helper`.
5
5
 
@@ -12,12 +12,12 @@ Feature: helper spec
12
12
  on the `helper` object.
13
13
 
14
14
  NOTE: helper methods defined in controllers are not included.
15
-
15
+
16
16
  Scenario: helper method that returns a value
17
17
  Given a file named "spec/helpers/application_helper_spec.rb" with:
18
18
  """
19
19
  require "spec_helper"
20
-
20
+
21
21
  describe ApplicationHelper do
22
22
  describe "#page_title" do
23
23
  it "returns the default title" do
@@ -36,7 +36,7 @@ Feature: helper spec
36
36
  """
37
37
  When I run `rspec spec/helpers/application_helper_spec.rb`
38
38
  Then the examples should all pass
39
-
39
+
40
40
  Scenario: helper method that accesses an instance variable
41
41
  Given a file named "spec/helpers/application_helper_spec.rb" with:
42
42
  """
@@ -68,10 +68,10 @@ Feature: helper spec
68
68
  require "spec_helper"
69
69
 
70
70
  describe WidgetsHelper do
71
- describe "#page_title" do
71
+ describe "#widget_title" do
72
72
  it "includes the app name" do
73
- assign(:title, "This Page")
74
- helper.page_title.should eq("The App: This Page")
73
+ assign(:title, "This Widget")
74
+ helper.widget_title.should eq("The App: This Widget")
75
75
  end
76
76
  end
77
77
  end
@@ -87,7 +87,7 @@ Feature: helper spec
87
87
  And a file named "app/helpers/widgets_helper.rb" with:
88
88
  """
89
89
  module WidgetsHelper
90
- def page_title
90
+ def widget_title
91
91
  "#{app_name}: #{@title}"
92
92
  end
93
93
  end
@@ -62,6 +62,7 @@ Feature: transactional examples
62
62
 
63
63
  RSpec.configure do |c|
64
64
  c.use_transactional_examples = false
65
+ c.order = "default"
65
66
  end
66
67
 
67
68
  describe Widget do
@@ -14,4 +14,4 @@ customized routes, like vanity links, slugs, etc.
14
14
 
15
15
  They are also valuable for routes that should not be available:
16
16
 
17
- { :delete => "/accounts/37" }.should_not be_routable
17
+ { :delete => "/accounts/37" }.should_not be_routable
@@ -56,3 +56,35 @@ Feature: route_to matcher
56
56
 
57
57
  When I run `rspec spec/routing/widgets_routing_spec.rb`
58
58
  Then the output should contain "1 failure"
59
+
60
+ Scenario: route spec for a namespaced route with shortcut specifier
61
+ Given a file named "spec/routing/admin_routing_spec.rb" with:
62
+ """
63
+ require "spec_helper"
64
+
65
+ describe "routes for Widgets" do
66
+ it "routes /admin/accounts to the admin/accounts controller" do
67
+ get("/admin/accounts").
68
+ should route_to("admin/accounts#index")
69
+ end
70
+ end
71
+ """
72
+
73
+ When I run `rspec spec/routing/admin_routing_spec.rb`
74
+ Then the examples should all pass
75
+
76
+ Scenario: route spec for a namespaced route with verbose specifier
77
+ Given a file named "spec/routing/admin_routing_spec.rb" with:
78
+ """
79
+ require "spec_helper"
80
+
81
+ describe "routes for Widgets" do
82
+ it "routes /admin/accounts to the admin/accounts controller" do
83
+ get("/admin/accounts").
84
+ should route_to(:controller => "admin/accounts", :action => "index")
85
+ end
86
+ end
87
+ """
88
+
89
+ When I run `rspec spec/routing/admin_routing_spec.rb`
90
+ Then the examples should all pass
@@ -2,7 +2,7 @@ require 'rails/generators/named_base'
2
2
 
3
3
  module Rspec
4
4
  module Generators
5
- class Base < Rails::Generators::NamedBase
5
+ class Base < ::Rails::Generators::NamedBase
6
6
  def self.source_root
7
7
  @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
8
8
  end
@@ -1,6 +1,6 @@
1
1
  module Rspec
2
2
  module Generators
3
- class InstallGenerator < Rails::Generators::Base
3
+ class InstallGenerator < ::Rails::Generators::Base
4
4
 
5
5
  desc <<DESC
6
6
  Description:
@@ -1 +1 @@
1
- --colour
1
+ --color
@@ -29,4 +29,10 @@ RSpec.configure do |config|
29
29
  # automatically. This will be the default behavior in future versions of
30
30
  # rspec-rails.
31
31
  config.infer_base_class_for_anonymous_controllers = false
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = "random"
32
38
  end
@@ -1,4 +1,4 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
2
 
3
3
  <% unless attributes.empty? -%>
4
4
  one:
@@ -4,7 +4,7 @@ require 'rails/generators/resource_helpers'
4
4
  module Rspec
5
5
  module Generators
6
6
  class ScaffoldGenerator < Base
7
- include Rails::Generators::ResourceHelpers
7
+ include ::Rails::Generators::ResourceHelpers
8
8
  source_paths << File.expand_path("../../helper/templates", __FILE__)
9
9
  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
10
10
 
@@ -35,11 +35,6 @@ module Rspec
35
35
  copy_view :show
36
36
  end
37
37
 
38
- # Invoke the helper using the controller name (pluralized)
39
- hook_for :helper, :as => :scaffold do |invoked|
40
- invoke invoked, [ controller_name ]
41
- end
42
-
43
38
  def generate_routing_spec
44
39
  return unless options[:routing_specs]
45
40
 
@@ -26,7 +26,7 @@ describe <%= controller_class_name %>Controller do
26
26
  def valid_attributes
27
27
  {}
28
28
  end
29
-
29
+
30
30
  # This should return the minimal set of values that should be in the session
31
31
  # in order to pass any filters (e.g. authentication) defined in
32
32
  # <%= controller_class_name %>Controller. Be sure to keep this updated too.
@@ -17,7 +17,7 @@ rescue LoadError
17
17
  end
18
18
  end
19
19
 
20
- require 'rspec/rails/matchers/render_template'
20
+ require 'rspec/rails/matchers/have_rendered'
21
21
  require 'rspec/rails/matchers/redirect_to'
22
22
  require 'rspec/rails/matchers/routing_matchers'
23
23
  require 'rspec/rails/matchers/be_new_record'
@@ -1,10 +1,13 @@
1
1
  module RSpec::Rails::Matchers
2
- class BeANew
3
- include RSpec::Matchers::BuiltIn::BaseMatcher
2
+ class BeANew < RSpec::Matchers::BuiltIn::BaseMatcher
3
+
4
+ def initialize(expected)
5
+ @expected = expected
6
+ end
4
7
 
5
8
  # @api private
6
9
  def matches?(actual)
7
- super
10
+ @actual = actual
8
11
  actual.is_a?(expected) && actual.new_record? && attributes_match?(actual)
9
12
  end
10
13
 
@@ -1,6 +1,5 @@
1
1
  module RSpec::Rails::Matchers
2
- class BeANewRecord
3
- include RSpec::Matchers::BuiltIn::BaseMatcher
2
+ class BeANewRecord < RSpec::Matchers::BuiltIn::BaseMatcher
4
3
 
5
4
  # @api private
6
5
  def matches?(actual)
@@ -1,10 +1,9 @@
1
1
  module RSpec::Rails::Matchers
2
2
  module RenderTemplate
3
- class RenderTemplateMatcher
4
- include RSpec::Matchers::BuiltIn::BaseMatcher
3
+ class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
5
4
 
6
5
  def initialize(scope, expected, message=nil)
7
- super(Symbol === expected ? expected.to_s : expected)
6
+ @expected = Symbol === expected ? expected.to_s : expected
8
7
  @message = message
9
8
  @scope = scope
10
9
  end
@@ -31,9 +30,11 @@ module RSpec::Rails::Matchers
31
30
  #
32
31
  # @example
33
32
  #
34
- # response.should render_template("new")
35
- def render_template(options, message=nil)
33
+ # response.should have_rendered("new")
34
+ def have_rendered(options, message=nil)
36
35
  RenderTemplateMatcher.new(self, options, message)
37
36
  end
37
+
38
+ alias_method :render_template, :have_rendered
38
39
  end
39
40
  end
@@ -1,17 +1,16 @@
1
1
  module RSpec::Rails::Matchers
2
2
  module RedirectTo
3
- class RedirectTo
4
- include RSpec::Matchers::BuiltIn::BaseMatcher
3
+ class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher
5
4
 
6
5
  def initialize(scope, expected)
7
- super(expected)
6
+ @expected = expected
8
7
  @scope = scope
9
8
  end
10
9
 
11
10
  # @api private
12
- def matches?(actual)
11
+ def matches?(_)
13
12
  match_unless_raises ActiveSupport::TestCase::Assertion do
14
- @scope.assert_redirected_to(expected)
13
+ @scope.assert_redirected_to(@expected)
15
14
  end
16
15
  end
17
16
 
@@ -22,7 +21,7 @@ module RSpec::Rails::Matchers
22
21
 
23
22
  # @api private
24
23
  def failure_message_for_should_not
25
- "expected not to redirect to #{expected.inspect}, but did"
24
+ "expected not to redirect to #{@expected.inspect}, but did"
26
25
  end
27
26
  end
28
27
 
@@ -2,33 +2,28 @@ module RSpec::Rails::Matchers
2
2
  module RoutingMatchers
3
3
  extend RSpec::Matchers::DSL
4
4
 
5
- class RouteToMatcher
6
- include RSpec::Matchers::BuiltIn::BaseMatcher
5
+ class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
7
6
 
8
7
  def initialize(scope, *expected)
9
8
  @scope = scope
10
- @expected_options = expected[1] || {}
9
+ @expected = expected[1] || {}
11
10
  if Hash === expected[0]
12
- @expected_options.merge!(expected[0])
11
+ @expected.merge!(expected[0])
13
12
  else
14
13
  controller, action = expected[0].split('#')
15
- @expected_options.merge!(:controller => controller, :action => action)
14
+ @expected.merge!(:controller => controller, :action => action)
16
15
  end
17
16
  end
18
17
 
19
- def description
20
- "route #{@verb_to_path_map.inspect} to #{@expected_options.inspect}"
21
- end
22
-
23
18
  # @api private
24
19
  def matches?(verb_to_path_map)
25
- @verb_to_path_map = verb_to_path_map
20
+ @actual = @verb_to_path_map = verb_to_path_map
26
21
  # assert_recognizes does not consider ActionController::RoutingError an
27
22
  # assertion failure, so we have to capture that and Assertion here.
28
23
  match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
29
24
  path, query = *verb_to_path_map.values.first.split('?')
30
25
  @scope.assert_recognizes(
31
- @expected_options,
26
+ @expected,
32
27
  {:method => verb_to_path_map.keys.first, :path => path},
33
28
  Rack::Utils::parse_query(query)
34
29
  )
@@ -39,6 +34,10 @@ module RSpec::Rails::Matchers
39
34
  def failure_message_for_should
40
35
  rescued_exception.message
41
36
  end
37
+
38
+ def description
39
+ "route #{@actual.inspect} to #{@expected.inspect}"
40
+ end
42
41
  end
43
42
 
44
43
  # Delegates to `assert_recognizes`. Supports short-hand controller/action
@@ -58,8 +57,7 @@ module RSpec::Rails::Matchers
58
57
  RouteToMatcher.new(self, *expected)
59
58
  end
60
59
 
61
- class BeRoutableMatcher
62
- include RSpec::Matchers::BuiltIn::BaseMatcher
60
+ class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
63
61
 
64
62
  def initialize(scope)
65
63
  @scope = scope
@@ -67,7 +65,7 @@ module RSpec::Rails::Matchers
67
65
 
68
66
  # @api private
69
67
  def matches?(path)
70
- super(path)
68
+ @actual = path
71
69
  match_unless_raises ActionController::RoutingError do
72
70
  @routing_options = @scope.routes.recognize_path(
73
71
  path.values.first, :method => path.keys.first
@@ -75,9 +73,12 @@ module RSpec::Rails::Matchers
75
73
  end
76
74
  end
77
75
 
78
- # @api private
76
+ def failure_message_for_should
77
+ "expected #{@actual.inspect} to be routable"
78
+ end
79
+
79
80
  def failure_message_for_should_not
80
- "expected #{actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
81
+ "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
81
82
  end
82
83
  end
83
84
 
@@ -114,11 +114,11 @@ EOM
114
114
  def @object.is_a?(other)
115
115
  #{model_class}.ancestors.include?(other)
116
116
  end unless #{stubs.has_key?(:is_a?)}
117
-
117
+
118
118
  def @object.kind_of?(other)
119
119
  #{model_class}.ancestors.include?(other)
120
120
  end unless #{stubs.has_key?(:kind_of?)}
121
-
121
+
122
122
  def @object.instance_of?(other)
123
123
  other == #{model_class}
124
124
  end unless #{stubs.has_key?(:instance_of?)}
@@ -130,7 +130,7 @@ EOM
130
130
  def @object.respond_to?(method_name, include_private=false)
131
131
  __model_class_has_column?(method_name) ? true : super
132
132
  end unless #{stubs.has_key?(:respond_to?)}
133
-
133
+
134
134
  def @object.method_missing(m, *a, &b)
135
135
  respond_to?(m) ? null_object? ? self : nil : super
136
136
  end
@@ -138,7 +138,7 @@ EOM
138
138
  def @object.class
139
139
  #{model_class}
140
140
  end unless #{stubs.has_key?(:class)}
141
-
141
+
142
142
  def @object.to_s
143
143
  "#{model_class.name}_#{to_param}"
144
144
  end unless #{stubs.has_key?(:to_s)}
@@ -181,12 +181,12 @@ EOM
181
181
  end
182
182
 
183
183
  # Creates an instance of `Model` with `to_param` stubbed using a
184
- # generated value that is unique to each object.. If `Model` is an
184
+ # generated value that is unique to each object. If `Model` is an
185
185
  # `ActiveRecord` model, it is prohibited from accessing the database*.
186
186
  #
187
- # For each key in `hash_of_stubs`, if the model has a matching attribute
188
- # (determined by asking it) are simply assigned the submitted values. If
189
- # the model does not have a matching attribute, the key/value pair is
187
+ # For each key in `stubs`, if the model has a matching attribute
188
+ # (determined by `respond_to?`) it is simply assigned the submitted values.
189
+ # If the model does not have a matching attribute, the key/value pair is
190
190
  # assigned as a stub return value using RSpec's mocking/stubbing
191
191
  # framework.
192
192
  #
@@ -240,7 +240,4 @@ EOM
240
240
  end
241
241
  end
242
242
 
243
- RSpec.configure do |c|
244
- c.include RSpec::Rails::Mocks
245
- end
246
-
243
+ RSpec.configuration.include RSpec::Rails::Mocks
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  module Version
4
- STRING = '2.10.1'
4
+ STRING = '2.11.0'
5
5
  end
6
6
  end
7
7
  end
@@ -33,7 +33,7 @@ describe Rspec::Generators::ModelGenerator do
33
33
  describe 'the fixtures' do
34
34
  subject { file('spec/fixtures/posts.yml') }
35
35
 
36
- it { should contain(Regexp.new('# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html')) }
36
+ it { should contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html')) }
37
37
  end
38
38
  end
39
39
 
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ %w[have_rendered render_template].each do |template_expectation|
4
+ describe template_expectation do
5
+ include RSpec::Rails::Matchers::RenderTemplate
6
+ let(:response) { ActionController::TestResponse.new }
7
+
8
+ context "given a hash" do
9
+ it "delegates to assert_template" do
10
+ self.should_receive(:assert_template).with({:this => "hash"}, "this message")
11
+ expect("response").to send(template_expectation, {:this => "hash"}, "this message")
12
+ end
13
+ end
14
+
15
+ context "given a string" do
16
+ it "delegates to assert_template" do
17
+ self.should_receive(:assert_template).with("this string", "this message")
18
+ expect("response").to send(template_expectation, "this string", "this message")
19
+ end
20
+ end
21
+
22
+ context "given a symbol" do
23
+ it "converts to_s and delegates to assert_template" do
24
+ self.should_receive(:assert_template).with("template_name", "this message")
25
+ expect("response").to send(template_expectation, :template_name, "this message")
26
+ end
27
+ end
28
+
29
+ context "with should" do
30
+ context "when assert_template passes" do
31
+ it "passes" do
32
+ self.stub!(:assert_template)
33
+ expect do
34
+ expect(response).to send(template_expectation, "template_name")
35
+ end.to_not raise_exception
36
+ end
37
+ end
38
+
39
+ context "when assert_template fails" do
40
+ it "uses failure message from assert_template" do
41
+ self.stub!(:assert_template) do
42
+ raise ActiveSupport::TestCase::Assertion.new("this message")
43
+ end
44
+ expect do
45
+ expect(response).to send(template_expectation, "template_name")
46
+ end.to raise_error("this message")
47
+ end
48
+ end
49
+
50
+ context "when fails due to some other exception" do
51
+ it "raises that exception" do
52
+ self.stub!(:assert_template) do
53
+ raise "oops"
54
+ end
55
+ expect do
56
+ expect(response).to send(template_expectation, "template_name")
57
+ end.to raise_exception("oops")
58
+ end
59
+ end
60
+ end
61
+
62
+ context "with should_not" do
63
+ context "when assert_template fails" do
64
+ it "passes" do
65
+ def assert_template(*)
66
+ raise ActiveSupport::TestCase::Assertion.new("this message")
67
+ end
68
+ expect do
69
+ expect(response).to_not send(template_expectation, "template_name")
70
+ end.to_not raise_exception
71
+ end
72
+ end
73
+
74
+ context "when assert_template passes" do
75
+ it "fails with custom failure message" do
76
+ def assert_template(*); end
77
+ expect do
78
+ expect(response).to_not send(template_expectation, "template_name")
79
+ end.to raise_error(/expected not to render \"template_name\", but did/)
80
+ end
81
+ end
82
+
83
+ context "when fails due to some other exception" do
84
+ it "raises that exception" do
85
+ def assert_template(*); raise "oops"; end
86
+ expect do
87
+ expect(response).to_not send(template_expectation, "template_name")
88
+ end.to raise_exception("oops")
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -6,15 +6,11 @@ describe "redirect_to" do
6
6
 
7
7
  let(:response) { ActionController::TestResponse.new }
8
8
 
9
- it "delegates to assert_redirected_to" do
10
- self.should_receive(:assert_redirected_to).with("destination")
11
- "response".should redirect_to("destination")
12
- end
13
-
14
9
  context "with should" do
15
10
  context "when assert_redirected_to passes" do
11
+ def assert_redirected_to(*); end
12
+
16
13
  it "passes" do
17
- self.stub!(:assert_redirected_to)
18
14
  expect do
19
15
  response.should redirect_to("destination")
20
16
  end.to_not raise_exception
@@ -22,21 +18,23 @@ describe "redirect_to" do
22
18
  end
23
19
 
24
20
  context "when assert_redirected_to fails" do
21
+ def assert_redirected_to(*)
22
+ raise ActiveSupport::TestCase::Assertion.new("this message")
23
+ end
24
+
25
25
  it "uses failure message from assert_redirected_to" do
26
- self.stub!(:assert_redirected_to) do
27
- raise ActiveSupport::TestCase::Assertion.new("this message")
28
- end
29
26
  expect do
30
27
  response.should redirect_to("destination")
31
- end.to raise_error("this message")
28
+ end.to raise_exception("this message")
32
29
  end
33
30
  end
34
31
 
35
32
  context "when fails due to some other exception" do
33
+ def assert_redirected_to(*)
34
+ raise "oops"
35
+ end
36
+
36
37
  it "raises that exception" do
37
- self.stub!(:assert_redirected_to) do
38
- raise "oops"
39
- end
40
38
  expect do
41
39
  response.should redirect_to("destination")
42
40
  end.to raise_exception("oops")
@@ -46,10 +44,11 @@ describe "redirect_to" do
46
44
 
47
45
  context "with should_not" do
48
46
  context "when assert_redirected_to fails" do
47
+ def assert_redirected_to(*)
48
+ raise ActiveSupport::TestCase::Assertion.new("this message")
49
+ end
50
+
49
51
  it "passes" do
50
- self.stub!(:assert_redirected_to) do
51
- raise ActiveSupport::TestCase::Assertion.new("this message")
52
- end
53
52
  expect do
54
53
  response.should_not redirect_to("destination")
55
54
  end.to_not raise_exception
@@ -57,19 +56,21 @@ describe "redirect_to" do
57
56
  end
58
57
 
59
58
  context "when assert_redirected_to passes" do
59
+ def assert_redirected_to(*); end
60
+
60
61
  it "fails with custom failure message" do
61
- self.stub!(:assert_redirected_to)
62
62
  expect do
63
63
  response.should_not redirect_to("destination")
64
- end.to raise_error(/expected not to redirect to \"destination\", but did/)
64
+ end.to raise_exception(/expected not to redirect to \"destination\", but did/)
65
65
  end
66
66
  end
67
67
 
68
68
  context "when fails due to some other exception" do
69
+ def assert_redirected_to(*)
70
+ raise "oops"
71
+ end
72
+
69
73
  it "raises that exception" do
70
- self.stub!(:assert_redirected_to) do
71
- raise "oops"
72
- end
73
74
  expect do
74
75
  response.should_not redirect_to("destination")
75
76
  end.to raise_exception("oops")
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: 2.10.1
4
+ version: 2.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-05 00:00:00.000000000 Z
12
+ date: 2012-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 2.10.0
69
+ version: 2.11.0
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 2.10.0
77
+ version: 2.11.0
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rake
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -209,9 +209,9 @@ files:
209
209
  - lib/rspec/rails/matchers/be_a_new.rb
210
210
  - lib/rspec/rails/matchers/be_new_record.rb
211
211
  - lib/rspec/rails/matchers/have_extension.rb
212
+ - lib/rspec/rails/matchers/have_rendered.rb
212
213
  - lib/rspec/rails/matchers/redirect_to.rb
213
214
  - lib/rspec/rails/matchers/relation_match_array.rb
214
- - lib/rspec/rails/matchers/render_template.rb
215
215
  - lib/rspec/rails/matchers/routing_matchers.rb
216
216
  - lib/rspec/rails/mocks.rb
217
217
  - lib/rspec/rails/module_inclusion.rb
@@ -290,9 +290,9 @@ files:
290
290
  - spec/rspec/rails/matchers/be_new_record_spec.rb
291
291
  - spec/rspec/rails/matchers/be_routable_spec.rb
292
292
  - spec/rspec/rails/matchers/errors_on_spec.rb
293
+ - spec/rspec/rails/matchers/have_rendered_spec.rb
293
294
  - spec/rspec/rails/matchers/redirect_to_spec.rb
294
295
  - spec/rspec/rails/matchers/relation_match_array_spec.rb
295
- - spec/rspec/rails/matchers/render_template_spec.rb
296
296
  - spec/rspec/rails/matchers/route_to_spec.rb
297
297
  - spec/rspec/rails/mocks/mock_model_spec.rb
298
298
  - spec/rspec/rails/mocks/stub_model_spec.rb
@@ -318,7 +318,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
318
318
  version: '0'
319
319
  segments:
320
320
  - 0
321
- hash: -3242320813797165557
321
+ hash: -673310072700950015
322
322
  required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  none: false
324
324
  requirements:
@@ -327,13 +327,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  version: '0'
328
328
  segments:
329
329
  - 0
330
- hash: -3242320813797165557
330
+ hash: -673310072700950015
331
331
  requirements: []
332
332
  rubyforge_project: rspec
333
333
  rubygems_version: 1.8.24
334
334
  signing_key:
335
335
  specification_version: 3
336
- summary: rspec-rails-2.10.1
336
+ summary: rspec-rails-2.11.0
337
337
  test_files:
338
338
  - features/Autotest.md
339
339
  - features/Generators.md
@@ -399,9 +399,9 @@ test_files:
399
399
  - spec/rspec/rails/matchers/be_new_record_spec.rb
400
400
  - spec/rspec/rails/matchers/be_routable_spec.rb
401
401
  - spec/rspec/rails/matchers/errors_on_spec.rb
402
+ - spec/rspec/rails/matchers/have_rendered_spec.rb
402
403
  - spec/rspec/rails/matchers/redirect_to_spec.rb
403
404
  - spec/rspec/rails/matchers/relation_match_array_spec.rb
404
- - spec/rspec/rails/matchers/render_template_spec.rb
405
405
  - spec/rspec/rails/matchers/route_to_spec.rb
406
406
  - spec/rspec/rails/mocks/mock_model_spec.rb
407
407
  - spec/rspec/rails/mocks/stub_model_spec.rb
@@ -1,91 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "render_template" do
4
- include RSpec::Rails::Matchers::RenderTemplate
5
- let(:response) { ActionController::TestResponse.new }
6
-
7
- context "given a hash" do
8
- it "delegates to assert_template" do
9
- self.should_receive(:assert_template).with({:this => "hash"}, "this message")
10
- "response".should render_template({:this => "hash"}, "this message")
11
- end
12
- end
13
-
14
- context "given a string" do
15
- it "delegates to assert_template" do
16
- self.should_receive(:assert_template).with("this string", "this message")
17
- "response".should render_template("this string", "this message")
18
- end
19
- end
20
-
21
- context "given a symbol" do
22
- it "converts to_s and delegates to assert_template" do
23
- self.should_receive(:assert_template).with("template_name", "this message")
24
- "response".should render_template(:template_name, "this message")
25
- end
26
- end
27
-
28
- context "with should" do
29
- context "when assert_template passes" do
30
- it "passes" do
31
- self.stub!(:assert_template)
32
- expect do
33
- response.should render_template("template_name")
34
- end.to_not raise_exception
35
- end
36
- end
37
-
38
- context "when assert_template fails" do
39
- it "uses failure message from assert_template" do
40
- self.stub!(:assert_template) do
41
- raise ActiveSupport::TestCase::Assertion.new("this message")
42
- end
43
- expect do
44
- response.should render_template("template_name")
45
- end.to raise_error("this message")
46
- end
47
- end
48
-
49
- context "when fails due to some other exception" do
50
- it "raises that exception" do
51
- self.stub!(:assert_template) do
52
- raise "oops"
53
- end
54
- expect do
55
- response.should render_template("template_name")
56
- end.to raise_exception("oops")
57
- end
58
- end
59
- end
60
-
61
- context "with should_not" do
62
- context "when assert_template fails" do
63
- it "passes" do
64
- def assert_template(*)
65
- raise ActiveSupport::TestCase::Assertion.new("this message")
66
- end
67
- expect do
68
- response.should_not render_template("template_name")
69
- end.to_not raise_exception
70
- end
71
- end
72
-
73
- context "when assert_template passes" do
74
- it "fails with custom failure message" do
75
- def assert_template(*); end
76
- expect do
77
- response.should_not render_template("template_name")
78
- end.to raise_error(/expected not to render \"template_name\", but did/)
79
- end
80
- end
81
-
82
- context "when fails due to some other exception" do
83
- it "raises that exception" do
84
- def assert_template(*); raise "oops"; end
85
- expect do
86
- response.should_not render_template("template_name")
87
- end.to raise_exception("oops")
88
- end
89
- end
90
- end
91
- end