RSpec story failing because create is not rendering 'show'

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?

On Fri, Sep 12, 2008 at 8:56 AM, Damian J. [email protected]
wrote:

}, :type => RailsStory do
end
And “the page should show”, "Product 1
if @product.save
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?

David

Are you saying this part should work:

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

because I’m getting nil for this step too.

On Fri, Sep 12, 2008 at 10:58 AM, Damian J. [email protected]
wrote:

David

Are you saying this part should work:

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

because I’m getting nil for this step too.

Is the request actually completing successfully? It seems like there
might be an exception that’s preventing the page from rendering.

Pat

David C. wrote:

To make that transition easy for you, I’d recommend either moving to
cucumber now, or at least taking the “decoupled step definitions”
approach within Story Runner. Check out http://pastie.org/271244 (with
the steps, story and output) and let me know if it makes sense to you.

HTH,
David

Thanks for that, unfortunately I am having problems installing the
Cucumber gem

ERROR: While executing gem … (Errno::ENOENT)
No such file or directory -
c:/ruby/lib/ruby/gems/1.8/gems/aslakhellesoy-cuc
umber-0.1.5/bin/cucumber

Phew, Thanks all for the input. Just need an outside eye to help me
find a stupid mistake. I am using JEdit (on a windows box,
unfortunately can’t afford a Mac at the moment!) I had renamed
Views/Product to Views/Products in JEdit but didn’t realise it doesn’t
update the actual file system.

I switched the debugger on and found the exception saying couldn’t find
the view in the specified path, check my file system and found the
problem.

It passes now.

Just need to try to get cucumber installed.

On Fri, Sep 12, 2008 at 10:01 AM, Pat M. [email protected] wrote:

Is the request actually completing successfully? It seems like there
might be an exception that’s preventing the page from rendering.

That is what it sounds like.

Also - once you get this working, there is a general style/approach
issue that you may want to ponder - what you’ve got there will output
something like this:

Given No products in the system
When I Post to
Then show template should be rendered
And the page should show
And the page should show
And Confirm the product was successfully saved

Obviously, this isn’t that helpful as the arguments don’t get
rendered. The approach you are taking has not really been recommended
for a while and will not be supported in Cucumber, which is probably
going to be replacing RSpec’s Story Runner.

To make that transition easy for you, I’d recommend either moving to
cucumber now, or at least taking the “decoupled step definitions”
approach within Story Runner. Check out http://pastie.org/271244 (with
the steps, story and output) and let me know if it makes sense to you.

HTH,
David

On Fri, Sep 12, 2008 at 11:22 AM, Damian J. [email protected]
wrote:

Thanks for that, unfortunately I am having problems installing the
Cucumber gem

ERROR: While executing gem … (Errno::ENOENT)
No such file or directory -
c:/ruby/lib/ruby/gems/1.8/gems/aslakhellesoy-cuc
umber-0.1.5/bin/cucumber

You don’t need the gem to use cucumber with Rails:

script/plugin install git://github.com/aslakhellesoy/cucumber.git
script/generate cucumber
rake features

If you still want the gem anyway, try doing it manually:

git clone git://github.com/aslakhellesoy/cucumber.git
cd cucumber
rake gem
rake install_gem

Cheers,
David

When ever I try to install a plugin from a git repository I just get:

removing: …/vendor/plugins/cucumber/.git

is this because I am on windows, or is there something I need to do?

David C. wrote:

On Fri, Sep 12, 2008 at 11:37 AM, David C. [email protected]
wrote:

script/plugin install git://github.com/aslakhellesoy/cucumber.git
script/generate cucumber
rake features

If you still want the gem anyway, try doing it manually:

git clone git://github.com/aslakhellesoy/cucumber.git
cd cucumber
rake gem
rake install_gem

FYI - I added a cheat for that:

cheat install_cucumber_gem

(If you don’t have cheat installed, then “gem install cheat”)

I have managed to get Cucumber installed along with all the dependancies
(I think) but am now getting the error

RuntimeError: Could not find [Webrat::TextField, Webrat::TextareaField,
Webr
at::PasswordField]: :name

In my “new” view the HTML produced includes this:

which I beleive is what should be there. Do you think this is a problem
with my setup?

On Fri, Sep 12, 2008 at 11:37 AM, David C. [email protected]
wrote:

script/plugin install git://github.com/aslakhellesoy/cucumber.git
script/generate cucumber
rake features

If you still want the gem anyway, try doing it manually:

git clone git://github.com/aslakhellesoy/cucumber.git
cd cucumber
rake gem
rake install_gem

FYI - I added a cheat for that:

cheat install_cucumber_gem

(If you don’t have cheat installed, then “gem install cheat”)

Ok I got my story to pass by changing the follwing snippet

When /I create a product named (.) described with (.)/ do |name,
description|
visits new_product_path
fills_in “product[name]”, :with => name
fills_in “product[description]”, :with => description
clicks_button “Create”
end

don’t know why it doesn’t work with this:

fills_in :name, :with => name

Webrat api specs say it should

On Sat, Sep 13, 2008 at 2:24 PM, Damian J. [email protected]
wrote:

don’t know why it doesn’t work with this:

fills_in :name, :with => name

Webrat api specs say it should

No it doesn’t. It says that the first argument is considered as an
HTML id, name or label. The id is product_name. The name is
product[name] and I can’t tell from what you posted if you have a
label “name”.

Zach


Zach D.
http://www.continuousthinking.com

David, are you suggesting I should use the method you posted on Pastie,
using stories or should I use Features as suggested on the Cucumber
site?