25 Jan 2012, 17:13
I posted this on stackoverflow but no love there. It’s probably a mistype on my end, though I’ve done a lot of combinations to find a nut. My simple Rails 3.1 app is templated from DanielKehoe’s on github. The user model seems to be figured out. It’s just when I start to build my first feature, a table for Reference Units as noted by my feature:
Feature: I want to have Reference Units that I can refer to so they can be used elsewhere. That way
they can be updated in one place. I want to create and edit these Units.
Given I am logged in as the following user:
| name | "Testy McUserton" |
| password | "please" |
| email | "firstname.lastname@example.org" |
Scenario: Adding Reference Units
When I go to the new Reference Units page
And I fill in the following:
| commodity | "corn" |
| language | "en" |
| wholesale unit | "xton" |
| retail unit | "xliter" |
| receipt unit | "dollar" |
Then it should create a new Reference Unit<\pre><\code>
And my steps:
<pre><code>Given /^I am logged in as the following user:$/ do |table|
When /^I go to the new Reference Units page$/ do
When /^I fill in the following:$/ do |table|
@reference_unit = Reference_unit.create!(table.rows_hash)
<pre><code>Then /^it should create a new Reference Unit$/ do
pending # express the regexp above with the code you wish you had
The first step has sign_up valid_user in its user_steps.rb and is passing. My holdup is when it attempts to access the model reference_units.rb.
Here is my feature/support/paths.rb that reflects where to find it.
<pre><code>when /the new Reference Units page/
I've avoided putting any model, controller and view per the best practices, hoping cucumber would prompt me. In frustration, I generated the model, controller, a blank view and a migration and that's when I got the Load Error below:
<pre><code>Scenario: Adding Reference Units # features/user_can_create_units.feature:10
When I go to the new Reference Units page # features/step_definitions/user_create_unit_reference.rb:6
Expected /Users/sam/apps/myapp/app/models/reference_unit.rb to define Reference_unit (LoadError)
./features/step_definitions/user_create_unit_reference.rb:7:in `/^I go to the new Reference Units page$/'
features/user_can_create_units.feature:11:in `When I go to the new Reference Units page'<\pre><\code>
I know the model is OK in its basic form because I can add a record using the console. So it's my implementation of cucumber that's failing. My cucumber is 1.2.0.
25 Jan 2012, 23:16
OK, I think I hit on the clue. Digging around, I used the—backtrace option on cucumber and it pointed me to a dependency with a key word of “const”. OK, it doesn’t like something in the text. Looking around for info on two-word models, I can tell that my model was correct: ReferenceUnit. But looking at my error output, it was looking for Reference_unit. So for laughs I altered the regex for that step to be “When /^I go to the new Reference units page$” the error went away. So the syntax of the first line of the step is important, and not ‘freestylin’ as I suspected.
26 Jan 2012, 09:09
Please reserve this forum for questions related to the material in the book. You can get general Cucumber help here:
You must be logged in to comment