Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

renames `render_template` to `have_rendered`.

Also aliases to `render_template` for backward compatibility
  • Loading branch information...
commit 6695a580ec2ed54193311baaac84f6358d4e7cbe 1 parent 0ad477a
@dchelimsky dchelimsky authored
View
3  Changelog.md
@@ -5,6 +5,9 @@ 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)
+
### 2.10.1 / 2012-05-03
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.0...v2.10.1)
View
2  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'
View
6 lib/rspec/rails/matchers/render_template.rb → lib/rspec/rails/matchers/have_rendered.rb
@@ -31,9 +31,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
View
93 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
View
91 spec/rspec/rails/matchers/render_template_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.