Sha256: 154b28caed669f45095a3a03c96aceb4f2367fa09289b50672b798dd8a11b71f

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

require 'rspec/rails/view_assigns'

module RSpec::Rails
  # Extends ActionView::TestCase::Behavior
  #
  # == Examples
  #
  #   describe RoleBasedDisplayHelper do
  #     describe "display_for" do
  #       context "given the role of the current user" do
  #         it "yields to the block" do
  #           helper.stub(:current_user) { double(:roles => ['admin'] }
  #           text = helper.display_for('admin') { "this text" }
  #           text.should eq("this text")
  #         end
  #       end
  #
  #       context "given a different role that that of the current user" do
  #         it "renders an empty String" do
  #           helper.stub(:current_user) { double(:roles => ['manager'] }
  #           text = helper.display_for('admin') { "this text" }
  #           text.should eq("")
  #         end
  #       end
  #     end
  #   end
  #
  module HelperExampleGroup
    extend ActiveSupport::Concern
    extend RSpec::Rails::ModuleInclusion

    include RSpec::Rails::RailsExampleGroup

    include ActionView::TestCase::Behavior
    include RSpec::Rails::ViewAssigns
    include RSpec::Rails::BrowserSimulators

    webrat do
      include Webrat::Matchers
    end

    module ClassMethods
      def determine_default_helper_class(ignore)
        describes
      end
    end

    module InstanceMethods
      # Returns an instance of ActionView::Base with the helper being specified
      # mixed in, along with any of the built-in rails helpers.
      def helper
        _view.tap {|v| v.assign(view_assigns)}
      end

    private

      def _controller_path
        example.example_group.describes.to_s.sub(/Helper/,'').underscore
      end
    end

    included do
      metadata[:type] = :helper

      before do
        controller.controller_path = _controller_path
      end
    end

    RSpec.configure &include_self_when_dir_matches('spec','helpers')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-rails-2.3.1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-2.3.0 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-2.2.1 lib/rspec/rails/example/helper_example_group.rb