diff --git a/Changelog.md b/Changelog.md index 388c9f38b0..3133c5bf22 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,19 @@ +### 2.11.0 / 2012-07-07 +[full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...v2.11.0) + +Enhancements + +* The generated `spec/spec_helper.rb` sets `config.order = "random"` so that + specs run in random order by default. +* rename `render_template` to `have_rendered` (and alias to `render_template` + for backward compatibility) + +Bug fixes + +* "uninitialized constant" errors are avoided when using using gems like + `rspec-rails-uncommitted` that define `Rspec::Rails` before `rspec-rails` + loads (Andy Lindeman) + ### 2.10.1 / 2012-05-03 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.0...v2.10.1) @@ -5,6 +21,8 @@ Bug fixes * fix regression introduced in 2.10.0 that broke integration with Devise (https://github.com/rspec/rspec-rails/issues/534) +* remove generation of helper specs when running the scaffold generator, as + Rails already does this (Jack Dempsey) ### 2.10.0 / 2012-05-03 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.9.0...v2.10.0) @@ -24,7 +42,7 @@ Bug fixes ### 2.9.0 / 2012-03-17 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.8.1...v2.9.0) -Enhancments +Enhancements * add description method to RouteToMatcher (John Wulff) * 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 >= [full changelog](http://github.com/rspec/rspec-rails/compare/v2.6.1...v2.7.0) -* Enhancments +* Enhancements * `ActiveRecord::Relation` can use the `=~` matcher (Andy Lindeman) * Make generated controller spec more consistent with regard to ids (Brent J. Nordquist) diff --git a/README.md b/README.md index b1694dface..02388746d2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rspec-rails-2 +# 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) rspec-2 for rails-3 with lightweight extensions to each @@ -130,7 +130,7 @@ users like to use extension libraries like FactoryGirl and Capybara: ```ruby describe "home page" do it "displays the user's username after successful login" do - user = Factory(:user, :username => "jdoe", :password => "secret") + user = FactoryGirl.create(:user, :username => "jdoe", :password => "secret") visit "/login" fill_in "Username", :with => "jdoe" fill_in "Password", :with => "secret" @@ -181,7 +181,7 @@ end describe WidgetsController do describe "GET index" do it "assigns all widgets to @widgets" do - widget = Factory(:widget) + widget = FactoryGirl.create(:widget) get :index assigns(:widgets).should eq([widget]) end diff --git a/features/controller_specs/render_views.feature b/features/controller_specs/render_views.feature index 931e06b4cd..2fbfa4fb01 100644 --- a/features/controller_specs/render_views.feature +++ b/features/controller_specs/render_views.feature @@ -71,7 +71,7 @@ Feature: render_views end end """ - When I run `rspec spec --format documentation` + When I run `rspec spec --order default --format documentation` Then the output should contain: """ WidgetsController diff --git a/features/helper_specs/helper_spec.feature b/features/helper_specs/helper_spec.feature index 26d16755db..5d39fa2e6a 100644 --- a/features/helper_specs/helper_spec.feature +++ b/features/helper_specs/helper_spec.feature @@ -1,5 +1,5 @@ Feature: helper spec - + Helper specs live in `spec/helpers`, or any example group with `:type => :helper`. @@ -12,12 +12,12 @@ Feature: helper spec on the `helper` object. NOTE: helper methods defined in controllers are not included. - + Scenario: helper method that returns a value Given a file named "spec/helpers/application_helper_spec.rb" with: """ require "spec_helper" - + describe ApplicationHelper do describe "#page_title" do it "returns the default title" do @@ -36,7 +36,7 @@ Feature: helper spec """ When I run `rspec spec/helpers/application_helper_spec.rb` Then the examples should all pass - + Scenario: helper method that accesses an instance variable Given a file named "spec/helpers/application_helper_spec.rb" with: """ @@ -68,10 +68,10 @@ Feature: helper spec require "spec_helper" describe WidgetsHelper do - describe "#page_title" do + describe "#widget_title" do it "includes the app name" do - assign(:title, "This Page") - helper.page_title.should eq("The App: This Page") + assign(:title, "This Widget") + helper.widget_title.should eq("The App: This Widget") end end end @@ -87,7 +87,7 @@ Feature: helper spec And a file named "app/helpers/widgets_helper.rb" with: """ module WidgetsHelper - def page_title + def widget_title "#{app_name}: #{@title}" end end diff --git a/features/model_specs/transactional_examples.feature b/features/model_specs/transactional_examples.feature index 703a581d47..283f8f4e3f 100644 --- a/features/model_specs/transactional_examples.feature +++ b/features/model_specs/transactional_examples.feature @@ -62,6 +62,7 @@ Feature: transactional examples RSpec.configure do |c| c.use_transactional_examples = false + c.order = "default" end describe Widget do diff --git a/features/routing_specs/README.md b/features/routing_specs/README.md index 533f7a5476..0473c3df56 100644 --- a/features/routing_specs/README.md +++ b/features/routing_specs/README.md @@ -14,4 +14,4 @@ customized routes, like vanity links, slugs, etc. They are also valuable for routes that should not be available: - { :delete => "/accounts/37" }.should_not be_routable + { :delete => "/accounts/37" }.should_not be_routable \ No newline at end of file diff --git a/features/routing_specs/route_to_matcher.feature b/features/routing_specs/route_to_matcher.feature index 08ddb68e86..59e3400b0d 100644 --- a/features/routing_specs/route_to_matcher.feature +++ b/features/routing_specs/route_to_matcher.feature @@ -56,3 +56,35 @@ Feature: route_to matcher When I run `rspec spec/routing/widgets_routing_spec.rb` Then the output should contain "1 failure" + + Scenario: route spec for a namespaced route with shortcut specifier + Given a file named "spec/routing/admin_routing_spec.rb" with: + """ + require "spec_helper" + + describe "routes for Widgets" do + it "routes /admin/accounts to the admin/accounts controller" do + get("/admin/accounts"). + should route_to("admin/accounts#index") + end + end + """ + + When I run `rspec spec/routing/admin_routing_spec.rb` + Then the examples should all pass + + Scenario: route spec for a namespaced route with verbose specifier + Given a file named "spec/routing/admin_routing_spec.rb" with: + """ + require "spec_helper" + + describe "routes for Widgets" do + it "routes /admin/accounts to the admin/accounts controller" do + get("/admin/accounts"). + should route_to(:controller => "admin/accounts", :action => "index") + end + end + """ + + When I run `rspec spec/routing/admin_routing_spec.rb` + Then the examples should all pass \ No newline at end of file diff --git a/lib/generators/rspec.rb b/lib/generators/rspec.rb index 3b1d9e4ea5..ef89550581 100644 --- a/lib/generators/rspec.rb +++ b/lib/generators/rspec.rb @@ -2,7 +2,7 @@ module Rspec module Generators - class Base < Rails::Generators::NamedBase + class Base < ::Rails::Generators::NamedBase def self.source_root @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates')) end diff --git a/lib/generators/rspec/install/install_generator.rb b/lib/generators/rspec/install/install_generator.rb index 76ecc79bad..cb09c490be 100644 --- a/lib/generators/rspec/install/install_generator.rb +++ b/lib/generators/rspec/install/install_generator.rb @@ -1,6 +1,6 @@ module Rspec module Generators - class InstallGenerator < Rails::Generators::Base + class InstallGenerator < ::Rails::Generators::Base desc < one: diff --git a/lib/generators/rspec/scaffold/scaffold_generator.rb b/lib/generators/rspec/scaffold/scaffold_generator.rb index afdcc44b69..7c48f95efe 100644 --- a/lib/generators/rspec/scaffold/scaffold_generator.rb +++ b/lib/generators/rspec/scaffold/scaffold_generator.rb @@ -4,7 +4,7 @@ module Rspec module Generators class ScaffoldGenerator < Base - include Rails::Generators::ResourceHelpers + include ::Rails::Generators::ResourceHelpers source_paths << File.expand_path("../../helper/templates", __FILE__) argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" @@ -35,11 +35,6 @@ def generate_view_specs copy_view :show end - # Invoke the helper using the controller name (pluralized) - hook_for :helper, :as => :scaffold do |invoked| - invoke invoked, [ controller_name ] - end - def generate_routing_spec return unless options[:routing_specs] diff --git a/lib/generators/rspec/scaffold/templates/controller_spec.rb b/lib/generators/rspec/scaffold/templates/controller_spec.rb index ccc259642e..e951980675 100644 --- a/lib/generators/rspec/scaffold/templates/controller_spec.rb +++ b/lib/generators/rspec/scaffold/templates/controller_spec.rb @@ -26,7 +26,7 @@ def valid_attributes {} end - + # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # <%= controller_class_name %>Controller. Be sure to keep this updated too. diff --git a/lib/rspec/rails/matchers.rb b/lib/rspec/rails/matchers.rb index b7756bfa81..fefdd9b75d 100644 --- a/lib/rspec/rails/matchers.rb +++ b/lib/rspec/rails/matchers.rb @@ -17,7 +17,7 @@ class AssertionFailedError < StandardError end end -require 'rspec/rails/matchers/render_template' +require 'rspec/rails/matchers/have_rendered' require 'rspec/rails/matchers/redirect_to' require 'rspec/rails/matchers/routing_matchers' require 'rspec/rails/matchers/be_new_record' diff --git a/lib/rspec/rails/matchers/be_a_new.rb b/lib/rspec/rails/matchers/be_a_new.rb index f08689c419..8bcdd99dd6 100644 --- a/lib/rspec/rails/matchers/be_a_new.rb +++ b/lib/rspec/rails/matchers/be_a_new.rb @@ -1,10 +1,13 @@ module RSpec::Rails::Matchers - class BeANew - include RSpec::Matchers::BuiltIn::BaseMatcher + class BeANew < RSpec::Matchers::BuiltIn::BaseMatcher + + def initialize(expected) + @expected = expected + end # @api private def matches?(actual) - super + @actual = actual actual.is_a?(expected) && actual.new_record? && attributes_match?(actual) end diff --git a/lib/rspec/rails/matchers/be_new_record.rb b/lib/rspec/rails/matchers/be_new_record.rb index 890f3bb304..2ff9709058 100644 --- a/lib/rspec/rails/matchers/be_new_record.rb +++ b/lib/rspec/rails/matchers/be_new_record.rb @@ -1,6 +1,5 @@ module RSpec::Rails::Matchers - class BeANewRecord - include RSpec::Matchers::BuiltIn::BaseMatcher + class BeANewRecord < RSpec::Matchers::BuiltIn::BaseMatcher # @api private def matches?(actual) diff --git a/lib/rspec/rails/matchers/render_template.rb b/lib/rspec/rails/matchers/have_rendered.rb similarity index 72% rename from lib/rspec/rails/matchers/render_template.rb rename to lib/rspec/rails/matchers/have_rendered.rb index f12c900673..7a0378f430 100644 --- a/lib/rspec/rails/matchers/render_template.rb +++ b/lib/rspec/rails/matchers/have_rendered.rb @@ -1,10 +1,9 @@ module RSpec::Rails::Matchers module RenderTemplate - class RenderTemplateMatcher - include RSpec::Matchers::BuiltIn::BaseMatcher + class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, expected, message=nil) - super(Symbol === expected ? expected.to_s : expected) + @expected = Symbol === expected ? expected.to_s : expected @message = message @scope = scope end @@ -31,9 +30,11 @@ def failure_message_for_should_not # # @example # - # response.should render_template("new") - def render_template(options, message=nil) + # response.should have_rendered("new") + def have_rendered(options, message=nil) RenderTemplateMatcher.new(self, options, message) end + + alias_method :render_template, :have_rendered end end diff --git a/lib/rspec/rails/matchers/redirect_to.rb b/lib/rspec/rails/matchers/redirect_to.rb index 8412bf094c..a0b09f5124 100644 --- a/lib/rspec/rails/matchers/redirect_to.rb +++ b/lib/rspec/rails/matchers/redirect_to.rb @@ -1,17 +1,16 @@ module RSpec::Rails::Matchers module RedirectTo - class RedirectTo - include RSpec::Matchers::BuiltIn::BaseMatcher + class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, expected) - super(expected) + @expected = expected @scope = scope end # @api private - def matches?(actual) + def matches?(_) match_unless_raises ActiveSupport::TestCase::Assertion do - @scope.assert_redirected_to(expected) + @scope.assert_redirected_to(@expected) end end @@ -22,7 +21,7 @@ def failure_message_for_should # @api private def failure_message_for_should_not - "expected not to redirect to #{expected.inspect}, but did" + "expected not to redirect to #{@expected.inspect}, but did" end end diff --git a/lib/rspec/rails/matchers/routing_matchers.rb b/lib/rspec/rails/matchers/routing_matchers.rb index 987b05acce..0330282af3 100644 --- a/lib/rspec/rails/matchers/routing_matchers.rb +++ b/lib/rspec/rails/matchers/routing_matchers.rb @@ -2,33 +2,28 @@ module RSpec::Rails::Matchers module RoutingMatchers extend RSpec::Matchers::DSL - class RouteToMatcher - include RSpec::Matchers::BuiltIn::BaseMatcher + class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, *expected) @scope = scope - @expected_options = expected[1] || {} + @expected = expected[1] || {} if Hash === expected[0] - @expected_options.merge!(expected[0]) + @expected.merge!(expected[0]) else controller, action = expected[0].split('#') - @expected_options.merge!(:controller => controller, :action => action) + @expected.merge!(:controller => controller, :action => action) end end - def description - "route #{@verb_to_path_map.inspect} to #{@expected_options.inspect}" - end - # @api private def matches?(verb_to_path_map) - @verb_to_path_map = verb_to_path_map + @actual = @verb_to_path_map = verb_to_path_map # assert_recognizes does not consider ActionController::RoutingError an # assertion failure, so we have to capture that and Assertion here. match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do path, query = *verb_to_path_map.values.first.split('?') @scope.assert_recognizes( - @expected_options, + @expected, {:method => verb_to_path_map.keys.first, :path => path}, Rack::Utils::parse_query(query) ) @@ -39,6 +34,10 @@ def matches?(verb_to_path_map) def failure_message_for_should rescued_exception.message end + + def description + "route #{@actual.inspect} to #{@expected.inspect}" + end end # Delegates to `assert_recognizes`. Supports short-hand controller/action @@ -58,8 +57,7 @@ def route_to(*expected) RouteToMatcher.new(self, *expected) end - class BeRoutableMatcher - include RSpec::Matchers::BuiltIn::BaseMatcher + class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope) @scope = scope @@ -67,7 +65,7 @@ def initialize(scope) # @api private def matches?(path) - super(path) + @actual = path match_unless_raises ActionController::RoutingError do @routing_options = @scope.routes.recognize_path( path.values.first, :method => path.keys.first @@ -75,9 +73,12 @@ def matches?(path) end end - # @api private + def failure_message_for_should + "expected #{@actual.inspect} to be routable" + end + def failure_message_for_should_not - "expected #{actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}" + "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}" end end diff --git a/lib/rspec/rails/mocks.rb b/lib/rspec/rails/mocks.rb index 86cda62eb5..6aef7254fc 100644 --- a/lib/rspec/rails/mocks.rb +++ b/lib/rspec/rails/mocks.rb @@ -114,11 +114,11 @@ def self.primary_key; :id; end def @object.is_a?(other) #{model_class}.ancestors.include?(other) end unless #{stubs.has_key?(:is_a?)} - + def @object.kind_of?(other) #{model_class}.ancestors.include?(other) end unless #{stubs.has_key?(:kind_of?)} - + def @object.instance_of?(other) other == #{model_class} end unless #{stubs.has_key?(:instance_of?)} @@ -130,7 +130,7 @@ def @object.__model_class_has_column?(method_name) def @object.respond_to?(method_name, include_private=false) __model_class_has_column?(method_name) ? true : super end unless #{stubs.has_key?(:respond_to?)} - + def @object.method_missing(m, *a, &b) respond_to?(m) ? null_object? ? self : nil : super end @@ -138,7 +138,7 @@ def @object.method_missing(m, *a, &b) def @object.class #{model_class} end unless #{stubs.has_key?(:class)} - + def @object.to_s "#{model_class.name}_#{to_param}" end unless #{stubs.has_key?(:to_s)} @@ -181,12 +181,12 @@ def connection end # Creates an instance of `Model` with `to_param` stubbed using a - # generated value that is unique to each object.. If `Model` is an + # generated value that is unique to each object. If `Model` is an # `ActiveRecord` model, it is prohibited from accessing the database*. # - # For each key in `hash_of_stubs`, if the model has a matching attribute - # (determined by asking it) are simply assigned the submitted values. If - # the model does not have a matching attribute, the key/value pair is + # For each key in `stubs`, if the model has a matching attribute + # (determined by `respond_to?`) it is simply assigned the submitted values. + # If the model does not have a matching attribute, the key/value pair is # assigned as a stub return value using RSpec's mocking/stubbing # framework. # @@ -240,7 +240,4 @@ def next_id end end -RSpec.configure do |c| - c.include RSpec::Rails::Mocks -end - +RSpec.configuration.include RSpec::Rails::Mocks diff --git a/lib/rspec/rails/version.rb b/lib/rspec/rails/version.rb index fdc572aec8..973ce1bd9e 100644 --- a/lib/rspec/rails/version.rb +++ b/lib/rspec/rails/version.rb @@ -1,7 +1,7 @@ module RSpec module Rails module Version - STRING = '2.10.1' + STRING = '2.11.0' end end end diff --git a/spec/generators/rspec/model/model_generator_spec.rb b/spec/generators/rspec/model/model_generator_spec.rb index 901a02b111..85a79c1702 100644 --- a/spec/generators/rspec/model/model_generator_spec.rb +++ b/spec/generators/rspec/model/model_generator_spec.rb @@ -33,7 +33,7 @@ describe 'the fixtures' do subject { file('spec/fixtures/posts.yml') } - it { should contain(Regexp.new('# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html')) } + it { should contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html')) } end end diff --git a/spec/rspec/rails/matchers/have_rendered_spec.rb b/spec/rspec/rails/matchers/have_rendered_spec.rb new file mode 100644 index 0000000000..1339d9c43d --- /dev/null +++ b/spec/rspec/rails/matchers/have_rendered_spec.rb @@ -0,0 +1,93 @@ +require "spec_helper" + +%w[have_rendered render_template].each do |template_expectation| + describe template_expectation do + include RSpec::Rails::Matchers::RenderTemplate + let(:response) { ActionController::TestResponse.new } + + context "given a hash" do + it "delegates to assert_template" do + self.should_receive(:assert_template).with({:this => "hash"}, "this message") + expect("response").to send(template_expectation, {:this => "hash"}, "this message") + end + end + + context "given a string" do + it "delegates to assert_template" do + self.should_receive(:assert_template).with("this string", "this message") + expect("response").to send(template_expectation, "this string", "this message") + end + end + + context "given a symbol" do + it "converts to_s and delegates to assert_template" do + self.should_receive(:assert_template).with("template_name", "this message") + expect("response").to send(template_expectation, :template_name, "this message") + end + end + + context "with should" do + context "when assert_template passes" do + it "passes" do + self.stub!(:assert_template) + expect do + expect(response).to send(template_expectation, "template_name") + end.to_not raise_exception + end + end + + context "when assert_template fails" do + it "uses failure message from assert_template" do + self.stub!(:assert_template) do + raise ActiveSupport::TestCase::Assertion.new("this message") + end + expect do + expect(response).to send(template_expectation, "template_name") + end.to raise_error("this message") + end + end + + context "when fails due to some other exception" do + it "raises that exception" do + self.stub!(:assert_template) do + raise "oops" + end + expect do + expect(response).to send(template_expectation, "template_name") + end.to raise_exception("oops") + end + end + end + + context "with should_not" do + context "when assert_template fails" do + it "passes" do + def assert_template(*) + raise ActiveSupport::TestCase::Assertion.new("this message") + end + expect do + expect(response).to_not send(template_expectation, "template_name") + end.to_not raise_exception + end + end + + context "when assert_template passes" do + it "fails with custom failure message" do + def assert_template(*); end + expect do + expect(response).to_not send(template_expectation, "template_name") + end.to raise_error(/expected not to render \"template_name\", but did/) + end + end + + context "when fails due to some other exception" do + it "raises that exception" do + def assert_template(*); raise "oops"; end + expect do + expect(response).to_not send(template_expectation, "template_name") + end.to raise_exception("oops") + end + end + end + end +end diff --git a/spec/rspec/rails/matchers/redirect_to_spec.rb b/spec/rspec/rails/matchers/redirect_to_spec.rb index b35d10adfd..a2fc2c646c 100644 --- a/spec/rspec/rails/matchers/redirect_to_spec.rb +++ b/spec/rspec/rails/matchers/redirect_to_spec.rb @@ -6,15 +6,11 @@ let(:response) { ActionController::TestResponse.new } - it "delegates to assert_redirected_to" do - self.should_receive(:assert_redirected_to).with("destination") - "response".should redirect_to("destination") - end - context "with should" do context "when assert_redirected_to passes" do + def assert_redirected_to(*); end + it "passes" do - self.stub!(:assert_redirected_to) expect do response.should redirect_to("destination") end.to_not raise_exception @@ -22,21 +18,23 @@ end context "when assert_redirected_to fails" do + def assert_redirected_to(*) + raise ActiveSupport::TestCase::Assertion.new("this message") + end + it "uses failure message from assert_redirected_to" do - self.stub!(:assert_redirected_to) do - raise ActiveSupport::TestCase::Assertion.new("this message") - end expect do response.should redirect_to("destination") - end.to raise_error("this message") + end.to raise_exception("this message") end end context "when fails due to some other exception" do + def assert_redirected_to(*) + raise "oops" + end + it "raises that exception" do - self.stub!(:assert_redirected_to) do - raise "oops" - end expect do response.should redirect_to("destination") end.to raise_exception("oops") @@ -46,10 +44,11 @@ context "with should_not" do context "when assert_redirected_to fails" do + def assert_redirected_to(*) + raise ActiveSupport::TestCase::Assertion.new("this message") + end + it "passes" do - self.stub!(:assert_redirected_to) do - raise ActiveSupport::TestCase::Assertion.new("this message") - end expect do response.should_not redirect_to("destination") end.to_not raise_exception @@ -57,19 +56,21 @@ end context "when assert_redirected_to passes" do + def assert_redirected_to(*); end + it "fails with custom failure message" do - self.stub!(:assert_redirected_to) expect do response.should_not redirect_to("destination") - end.to raise_error(/expected not to redirect to \"destination\", but did/) + end.to raise_exception(/expected not to redirect to \"destination\", but did/) end end context "when fails due to some other exception" do + def assert_redirected_to(*) + raise "oops" + end + it "raises that exception" do - self.stub!(:assert_redirected_to) do - raise "oops" - end expect do response.should_not redirect_to("destination") end.to raise_exception("oops") diff --git a/spec/rspec/rails/matchers/render_template_spec.rb b/spec/rspec/rails/matchers/render_template_spec.rb deleted file mode 100644 index b63cf77216..0000000000 --- a/spec/rspec/rails/matchers/render_template_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -require "spec_helper" - -describe "render_template" do - include RSpec::Rails::Matchers::RenderTemplate - let(:response) { ActionController::TestResponse.new } - - context "given a hash" do - it "delegates to assert_template" do - self.should_receive(:assert_template).with({:this => "hash"}, "this message") - "response".should render_template({:this => "hash"}, "this message") - end - end - - context "given a string" do - it "delegates to assert_template" do - self.should_receive(:assert_template).with("this string", "this message") - "response".should render_template("this string", "this message") - end - end - - context "given a symbol" do - it "converts to_s and delegates to assert_template" do - self.should_receive(:assert_template).with("template_name", "this message") - "response".should render_template(:template_name, "this message") - end - end - - context "with should" do - context "when assert_template passes" do - it "passes" do - self.stub!(:assert_template) - expect do - response.should render_template("template_name") - end.to_not raise_exception - end - end - - context "when assert_template fails" do - it "uses failure message from assert_template" do - self.stub!(:assert_template) do - raise ActiveSupport::TestCase::Assertion.new("this message") - end - expect do - response.should render_template("template_name") - end.to raise_error("this message") - end - end - - context "when fails due to some other exception" do - it "raises that exception" do - self.stub!(:assert_template) do - raise "oops" - end - expect do - response.should render_template("template_name") - end.to raise_exception("oops") - end - end - end - - context "with should_not" do - context "when assert_template fails" do - it "passes" do - def assert_template(*) - raise ActiveSupport::TestCase::Assertion.new("this message") - end - expect do - response.should_not render_template("template_name") - end.to_not raise_exception - end - end - - context "when assert_template passes" do - it "fails with custom failure message" do - def assert_template(*); end - expect do - response.should_not render_template("template_name") - end.to raise_error(/expected not to render \"template_name\", but did/) - end - end - - context "when fails due to some other exception" do - it "raises that exception" do - def assert_template(*); raise "oops"; end - expect do - response.should_not render_template("template_name") - end.to raise_exception("oops") - end - end - end -end