[rspec-users] RSpec story failing because create is not rendering 'show'

Damian Jones lists at ruby-forum.com
Fri Sep 12 09:56:42 EDT 2008


This is my story:

require File.expand_path(File.dirname(__FILE__) + "/helper")

Story "Creating a Product", %{
        As a User
        I want to create a product
        So that I can collect purchase options together under a specific
product

}, :type => RailsStory do

                Scenario "User with create product permissions" do
                        Given "No products in the system" do
                                Product.destroy_all
                        end

                        When "I Post  to", "/products", :product =>
{:name => "Product
1", :description => "Product 1 description"} do |path, params|
                                post_via_redirect path, params
                        end

                        Then "show template should be rendered" do
                                response.should render_template("show")
                        end

                        And "the page should show", "Product 1" do
|text|
                                response.should have_text(/#{text}/)
                        end

                        And "the page should show", "Product 1
description"

                        And "Confirm the product was successfully saved"
                end
end

and this is my create method(pretty standard)

       def create
                @product = Product.new params[:product]
                if @product.save
                        redirect_to product_url(@product)
                else
                        render :action => :new
                end
        end

My specs confirm that 'show' template is rendered after successful
save but my story is failing here:

                        Then "show template should be rendered" do
                                response.should render_template("show")
                        end

saying expected 'show' got nil.

I am new to Ruby and am trying to start off in the right way, but this
is driving me nuts,  any one got any ideas?
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list