Sha256: 83d2b1f4254d62c3eb5cd576166aed64773fb48f81df46d05f6489f3d2b64fc6

Contents?: true

Size: 1.58 KB

Versions: 20

Compression:

Stored size: 1.58 KB

Contents

Feature: stub template

  In order to isolate view specs from the partials rendered by the primary
  view, rspec-rails (since 2.2) provides the stub_template method.

  Scenario: stub template that does not exist
    Given a file named "spec/views/gadgets/list.html.erb_spec.rb" with:
      """
      require "spec_helper"

      describe "gadgets/list" do
        it "renders the gadget partial for each gadget" do
          assign(:gadgets, [
            mock_model(Gadget, :id => 1, :name => "First"),
            mock_model(Gadget, :id => 2, :name => "Second")
          ])
          stub_template "gadgets/_gadget.html.erb" => "<%= gadget.name %><br/>"
          render
          rendered.should =~ /First/
          rendered.should =~ /Second/
        end
      end
      """

    And a file named "app/views/gadgets/list.html.erb" with:
      """
      <%= render :partial => "gadget", :collection => @gadgets %>
      """
    When I run `rspec spec/views/gadgets/list.html.erb_spec.rb`
    Then the examples should all pass

  Scenario: stub template that exists
    Given a file named "spec/views/gadgets/edit.html.erb_spec.rb" with:
      """
      require "spec_helper"

      describe "gadgets/edit" do
        before(:each) do
          @gadget = assign(:gadget, stub_model(Gadget))
        end

        it "renders the form partial" do
          stub_template "gadgets/_form.html.erb" => "This content"
          render
          rendered.should =~ /This content/
        end
      end
      """
    When I run `rspec spec/views/gadgets/edit.html.erb_spec.rb`
    Then the examples should all pass

Version data entries

20 entries across 15 versions & 4 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
rspec-rails-2.11.4 features/view_specs/stub_template.feature
gem_repackager-0.1.0 support/gems/rspec-rails-2.11.0/features/view_specs/stub_template.feature
rspec-rails-2.11.0 features/view_specs/stub_template.feature
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/view_specs/stub_template.feature
rspec-rails-2.10.1 features/view_specs/stub_template.feature
rspec-rails-2.10.0 features/view_specs/stub_template.feature
rspec-rails-2.9.0 features/view_specs/stub_template.feature
rspec-rails-2.9.0.rc2 features/view_specs/stub_template.feature