changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/lib/spec/rails/example/helper_example_group.rb

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
1module Spec
2 module Rails
3 module Example
4 # Helper Specs live in $RAILS_ROOT/spec/helpers/.
5 #
6 # Helper Specs use Spec::Rails::Example::HelperExampleGroup, which allows you to
7 # include your Helper directly in the context and write specs directly
8 # against its methods.
9 #
10 # HelperExampleGroup also includes the standard lot of ActionView::Helpers in case your
11 # helpers rely on any of those.
12 #
13 # == Example
14 #
15 # class ThingHelper
16 # def number_of_things
17 # Thing.count
18 # end
19 # end
20 #
21 # describe "ThingHelper example_group" do
22 # include ThingHelper
23 # it "should tell you the number of things" do
24 # Thing.should_receive(:count).and_return(37)
25 # number_of_things.should == 37
26 # end
27 # end
28 class HelperExampleGroup < FunctionalExampleGroup
29 class << self
30 # The helper name....
31 def helper_name(name=nil)
32 send :include, "#{name}_helper".camelize.constantize
33 end
34 end
35
36 # Reverse the load order so that custom helpers which
37 # are defined last are also loaded last.
38 ActionView::Base.included_modules.reverse.each do |mod|
39 include mod if mod.parents.include?(ActionView::Helpers)
40 end
41
42 before(:all) do
43 @controller_class_name = 'Spec::Rails::Example::HelperBehaviourController'
44 end
45
46 before(:each) do
47 @controller.request = @request
48 @controller.url = ActionController::UrlRewriter.new @request, {} # url_for
49
50 @flash = ActionController::Flash::FlashHash.new
51 session['flash'] = @flash
52
53 ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
54 end
55
56 def flash
57 @flash
58 end
59
60 def eval_erb(text)
61 ERB.new(text).result(binding)
62 end
63
64
65 # TODO: BT - Helper Examples should proxy method_missing to a Rails View instance.
66 # When that is done, remove this method
67 def protect_against_forgery?
68 false
69 end
70
71 Spec::Example::ExampleGroupFactory.register(:helper, self)
72 end
73
74 class HelperBehaviourController < ApplicationController #:nodoc:
75 attr_accessor :request, :url
76
77 # Re-raise errors
78 def rescue_action(e); raise e; end
79 end
80 end
81 end
82end