Search code examples
rspeccucumberbddruby-on-rails-3webrat

Cucumber weird routes problem


I'm doing a simple app in rails without using cucumber

I have this user story:

Scenario: add new expense
  Given I am on the expenses page
  When I follow "new expense"
  Then I am on new expense page
  Then I fill in "expense_title" with "french fries"
  Then I fill in "expense_category" with "Lunch"
  Then I fill in "expense_amount" with "2300"
  And I press "expense_submit" 
  And I should be on the "french fries" expense page
  Then I should see "The expense was successfully created"

In development mode I followed the same steps and I got the expected results, but running this with cucumber I get this error message

(::) failed steps (::)

expected: "/expenses/2",
     got: "/expenses" (using ==) (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:260:in `/^(?:|I )should be on (.+)$/'
features/expenses.feature:14:in `And I should be on the "french fries" expense page'

I already set the correct path in the path.rb

when /the "(.+)" expense page/
      "/expenses/#{Expense.find_by_title($1).id}"

because of that, the expected path corresponding to the result of the previous code, it's right, but the got result don't.

When I added the "Then show me the page" after submitting the button I get a simple page with this message:

You are being redirected.

But as I said before this doesn't happen in development mode and also I've checked that the record is successfully stored into the database, so I don't know where could be the problem, Does anyone can help me please?

Greetings

PS: my create method

respond_to :html

def create
    @expense = Expense.new(params[:expense])

    if @expense.save
      flash[:notice] = "The expense was successfully created"
    end

    respond_with @expense
  end

Solution

  • The problem was a webrat compatibility issue with rails 3,

    It was the same problem of this, and there is the solution, a simple patch to the webrat gem