Browse files

expose render_template to view specs

  • Loading branch information...
1 parent 321a2e7 commit 3def656c6b447e224831a577d96f09498150b2a7 @dchelimsky dchelimsky committed Jun 18, 2010
View
3 lib/rspec/rails/example/controller_example_group.rb
@@ -83,7 +83,8 @@ module ControllerExampleGroup
include Webrat::Matchers
include Webrat::Methods
include RSpec::Matchers
- include RSpec::Rails::ControllerSpecMatchers
+ include RSpec::Rails::Matchers::RedirectTo
+ include RSpec::Rails::Matchers::RenderTemplate
module ClassMethods
def controller_class
View
3 lib/rspec/rails/example/request_example_group.rb
@@ -23,7 +23,8 @@ module RequestExampleGroup
include Webrat::Matchers
include Webrat::Methods
include RSpec::Matchers
- include RSpec::Rails::ControllerSpecMatchers
+ include RSpec::Rails::Matchers::RedirectTo
+ include RSpec::Rails::Matchers::RenderTemplate
include ActionController::TemplateAssertions
module InstanceMethods
View
5 lib/rspec/rails/example/view_example_group.rb
@@ -26,6 +26,7 @@ module ViewExampleGroup
include ActionView::TestCase::Behavior
include RSpec::Rails::ViewAssigns
include Webrat::Matchers
+ include RSpec::Rails::Matchers::RenderTemplate
module InstanceMethods
# :call-seq:
@@ -93,6 +94,10 @@ def _controller_path
included do
before do
controller.controller_path = _controller_path
+ # this won't be necessary if/when
+ # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4903
+ # is accepted and released
+ @request ||= controller.request
end
end
View
25 lib/rspec/rails/matchers.rb
@@ -1,5 +1,26 @@
-require 'rspec/rails/matchers/controller_spec_matchers'
-require 'rspec/rails/matchers/controller_spec_matchers'
+module RSpec::Rails
+ module Matchers
+ end
+end
+
+begin
+ require 'test/unit/assertionfailederror'
+rescue LoadError
+ module Test
+ module Unit
+ class AssertionFailedError < StandardError
+ end
+ end
+ end
+end
+
+begin
+ require "action_controller"
+rescue LoadError
+end
+
+require 'rspec/rails/matchers/render_template'
+require 'rspec/rails/matchers/redirect_to'
require 'rspec/rails/matchers/routing_spec_matchers'
require 'rspec/rails/matchers/model_matchers'
require 'rspec/rails/matchers/matcher_extensions'
View
46 lib/rspec/rails/matchers/controller_spec_matchers.rb
@@ -1,46 +0,0 @@
-require 'rspec/core/deprecation'
-require 'rspec/core/backward_compatibility'
-require 'rspec/matchers'
-
-begin
- require 'test/unit/assertionfailederror'
-rescue LoadError
- module Test
- module Unit
- class AssertionFailedError < StandardError
- end
- end
- end
-end
-
-begin
- require "action_controller"
-rescue LoadError
-end
-
-module RSpec::Rails
- module ControllerSpecMatchers
- extend RSpec::Matchers::DSL
-
- matcher :redirect_to do |destination|
- match_unless_raises Test::Unit::AssertionFailedError do |_|
- assert_redirected_to destination
- end
-
- failure_message_for_should do
- rescued_exception.message
- end
- end
-
- matcher :render_template do |options, message|
- match_unless_raises Test::Unit::AssertionFailedError do |_|
- options = options.to_s if Symbol === options
- assert_template options, message
- end
-
- failure_message_for_should do
- rescued_exception.message
- end
- end
- end
-end
View
15 lib/rspec/rails/matchers/redirect_to.rb
@@ -0,0 +1,15 @@
+module RSpec::Rails::Matchers
+ module RedirectTo
+ extend RSpec::Matchers::DSL
+
+ matcher :redirect_to do |destination|
+ match_unless_raises Test::Unit::AssertionFailedError do |_|
+ assert_redirected_to destination
+ end
+
+ failure_message_for_should do
+ rescued_exception.message
+ end
+ end
+ end
+end
View
16 lib/rspec/rails/matchers/render_template.rb
@@ -0,0 +1,16 @@
+module RSpec::Rails::Matchers
+ module RenderTemplate
+ extend RSpec::Matchers::DSL
+
+ matcher :render_template do |options, message|
+ match_unless_raises Test::Unit::AssertionFailedError do |_|
+ options = options.to_s if Symbol === options
+ assert_template options, message
+ end
+
+ failure_message_for_should do
+ rescued_exception.message
+ end
+ end
+ end
+end
View
2 spec/rspec/rails/matchers/redirect_to_spec.rb
@@ -2,7 +2,7 @@
require "action_controller/test_case"
describe "redirect_to" do
- include RSpec::Rails::ControllerSpecMatchers
+ include RSpec::Rails::Matchers::RedirectTo
it "delegates to assert_redirected_to" do
self.should_receive(:assert_redirected_to).with("destination")
View
2 spec/rspec/rails/matchers/render_template_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"
describe "render_template" do
- include RSpec::Rails::ControllerSpecMatchers
+ include RSpec::Rails::Matchers::RenderTemplate
it "uses failure message from render_template" do
self.stub!(:assert_template).and_raise(

1 comment on commit 3def656

@kristianmandrup

Sweet :)

Please sign in to comment.