Skip to content

Commit

Permalink
expose render_template to view specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jun 19, 2010
1 parent 321a2e7 commit 3def656
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 52 deletions.
3 changes: 2 additions & 1 deletion lib/rspec/rails/example/controller_example_group.rb
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/rspec/rails/example/request_example_group.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
25 changes: 23 additions & 2 deletions 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'
46 changes: 0 additions & 46 deletions lib/rspec/rails/matchers/controller_spec_matchers.rb

This file was deleted.

15 changes: 15 additions & 0 deletions 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
16 changes: 16 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion spec/rspec/rails/matchers/redirect_to_spec.rb
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion 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(
Expand Down

0 comments on commit 3def656

Please sign in to comment.