Module: RSpec::Rails::ViewExampleGroup::ExampleMethods

### Home Classes Methods

### In Files

- lib/rspec/rails/example/view_example_group.rb

### Methods

- #params
- #render
- #response
- #stub_template
- #template
- #view

### Files

- fixture

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Rails
- RSpec::Rails::AssertionDelegator
- RSpec::Rails::ControllerExampleGroup
- RSpec::Rails::ControllerExampleGroup::BypassRescue
- RSpec::Rails::ControllerExampleGroup::ClassMethods
- RSpec::Rails::Extensions
- RSpec::Rails::Extensions::ActiveRecord
- RSpec::Rails::FeatureExampleGroup
- RSpec::Rails::FixtureSupport
- RSpec::Rails::HelperExampleGroup
- RSpec::Rails::HelperExampleGroup::ClassMethods
- RSpec::Rails::IllegalDataAccessException
- RSpec::Rails::MailerExampleGroup
- RSpec::Rails::MailerExampleGroup::ClassMethods
- RSpec::Rails::Matchers
- RSpec::Rails::Matchers::BeANew
- RSpec::Rails::Matchers::BeANewRecord
- RSpec::Rails::Matchers::BeValid
- RSpec::Rails::Matchers::HaveExtensions
- RSpec::Rails::Matchers::RedirectTo
- RSpec::Rails::Matchers::RedirectTo::RedirectTo
- RSpec::Rails::Matchers::RenderTemplate
- RSpec::Rails::Matchers::RenderTemplate::RenderTemplateMatcher
- RSpec::Rails::Matchers::RoutingMatchers
- RSpec::Rails::Matchers::RoutingMatchers::BeRoutableMatcher
- RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
- RSpec::Rails::Matchers::RoutingMatchers::RouteToMatcher
- RSpec::Rails::MiniTestLifecycleAdapter
- RSpec::Rails::MinitestCounters
- RSpec::Rails::Mocks
- RSpec::Rails::Mocks::ActiveModelInstanceMethods
- RSpec::Rails::Mocks::ActiveModelStubExtensions
- RSpec::Rails::Mocks::ActiveRecordInstanceMethods
- RSpec::Rails::Mocks::ActiveRecordStubExtensions
- RSpec::Rails::ModelExampleGroup
- RSpec::Rails::ModuleInclusion
- RSpec::Rails::RailsExampleGroup
- RSpec::Rails::Railtie
- RSpec::Rails::RequestExampleGroup
- RSpec::Rails::RoutingExampleGroup
- RSpec::Rails::RoutingExampleGroup::ClassMethods
- RSpec::Rails::SetupAndTeardownAdapter
- RSpec::Rails::SetupAndTeardownAdapter::ClassMethods
- RSpec::Rails::TestUnitAssertionAdapter
- RSpec::Rails::TestUnitAssertionAdapter::AssertionDelegator
- RSpec::Rails::TestUnitAssertionAdapter::ClassMethods
- RSpec::Rails::Version
- RSpec::Rails::ViewAssigns
- RSpec::Rails::ViewExampleGroup
- RSpec::Rails::ViewExampleGroup::ClassMethods
- RSpec::Rails::ViewExampleGroup::ExampleMethods
- RSpec::Rails::ViewRendering
- RSpec::Rails::ViewRendering::ClassMethods
- RSpec::Rails::ViewRendering::EmptyTemplateHandler
- RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator
- RSpec::Rails::ViewRendering::EmptyTemplates
- Rspec
- Rspec::Generators
- Rspec::Generators::Base
- Rspec::Generators::ControllerGenerator
- Rspec::Generators::HelperGenerator
- Rspec::Generators::InstallGenerator
- Rspec::Generators::IntegrationGenerator
- Rspec::Generators::MailerGenerator
- Rspec::Generators::ModelGenerator
- Rspec::Generators::ObserverGenerator
- Rspec::Generators::ScaffoldGenerator
- Rspec::Generators::ViewGenerator
- Rails
- Rails::Generators
- Rails::Generators::GeneratedAttribute
- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- ActiveModel
- ActiveModel::Validations
- ActiveRecord
- ActiveRecord::Base
- Autotest
- Autotest::RailsRspec2
- Object
- RequestInstanceMethods

No matching classes.

# RSpec::Rails::ViewExampleGroup::ExampleMethods

### Public Instance Methods

params() click to toggle source

Provides access to the params hash that will be available within the view:

    params[:foo] = 'bar'

    # File lib/rspec/rails/example/view_example_group.rb, line 79
    def params
      controller.params
    end

render(options={}, local_assigns={}, &block) click to toggle source

@overload render @overload render({:partial => path_to_file}) @overload render({:partial => path_to_file}, {... locals ...}) @overload render({:partial => path_to_file}, {... locals ...}) do ... end

Delegates to ActionView::Base#render, so see documentation on that for more info.

The only addition is that you can call render with no arguments, and RSpec will pass the top level description to render:

    describe "widgets/new.html.erb" do
      it "shows all the widgets" do
        render # => view.render(:file => "widgets/new.html.erb")
        # ...
      end
    end

    # File lib/rspec/rails/example/view_example_group.rb, line 44
    def render(options={}, local_assigns={}, &block)
      options = _default_render_options if Hash === options and options.empty?
      super(options, local_assigns, &block)
    end

response() click to toggle source

@deprecated Use `rendered` instead.

    # File lib/rspec/rails/example/view_example_group.rb, line 90
    def response
      # `assert_template` expects `response` to implement a #body method
      # like an `ActionDispatch::Response` does to force the view to render.
      # For backwards compatibility, we use #response as an alias for
      # #rendered, but it needs to implement #body to avoid `assert_template`
      # raising a `NoMethodError`.
      unless rendered.respond_to?(:body)
        def rendered.body; self; end;
      end

      rendered
    end

stub_template(hash) click to toggle source

Simulates the presence of a template on the file system by adding a Rails' FixtureResolver to the front of the view_paths list. Designed to help isolate view examples from partials rendered by the view template that is the subject of the example.

@example

    stub_template("widgets/_widget.html.erb" => "This content.")

    # File lib/rspec/rails/example/view_example_group.rb, line 71
    def stub_template(hash)
      view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
    end

template() click to toggle source

@deprecated Use `view` instead.

    # File lib/rspec/rails/example/view_example_group.rb, line 84
    def template
      RSpec.deprecate("template", :replacement => "view")
      view
    end

view() click to toggle source

The instance of `ActionView::Base` that is used to render the template. Use this to stub methods before calling `render`.

    describe "widgets/new.html.erb" do
      it "shows all the widgets" do
        view.stub(:foo) { "foo" }
        render
        # ...
      end
    end

    # File lib/rspec/rails/example/view_example_group.rb, line 59
    def view
      _view
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.