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

David Chelimsky dchelimsky at gmail.com
Fri Sep 12 10:04:42 EDT 2008


On Fri, Sep 12, 2008 at 8:56 AM, Damian Jones <lists at ruby-forum.com> wrote:
> 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?

Stories don't provide access to internals like which template was
rendered. In this case, other steps are expecting text that's on the
resulting page. At a Story level, that's really all you need. You just
need to find the things on this particular page that will
differentiate it from other pages.

That make sense?


More information about the rspec-users mailing list