uninitialized constant User (NameError)

107 views
Skip to first unread message

martins

unread,
Aug 1, 2009, 5:15:36 AM8/1/09
to Cukes
Hi,

User is available in console in both test and development
environments.
But for some reason I get a NameError when running script/cucumber.

$ script/cucumber features/step_definitions/
main_view_descriptions.feature
And I´m logged in as a user # features/
step_definitions/main_view_steps.rb:5
uninitialized constant User (NameError)
./features/step_definitions/main_view_steps.rb:6:in `/^I0264m
logged in as a user$/'
features/step_definitions/main_view_descriptions.feature:8:in
`And I´m logged in as a user'


## main_view_steps.rb
Given /^I´m logged in as a user$/ do
@user = User.create(:name => "martin")
end


## Testing from console
$ ruby script/console test
Loading test environment (Rails 2.3.3)
>> @user = User.create(:name => "martin")
=> #<User id: 4, name: "martin", created_at: "2009-08-01 08:11:51",
updated_at: "2009-08-01 08:11:51">


*** LOCAL GEMS ***

cucumber (0.3.92)
rails (2.3.3
rspec (1.2.8)
rspec-rails (1.2.7.1)




Any idea what might be wrong? Cucumber works in test-environment,
right?


Cheers,
Martins

aslak hellesoy

unread,
Aug 1, 2009, 5:41:39 AM8/1/09
to cu...@googlegroups.com
Hi,

User is available in console in both test and development
environments.
But for some reason I get a NameError when running script/cucumber. 

$ script/cucumber features/step_definitions/

You have features under step_definitions? Only ruby files are supposed to go there. When you run like this, nothing under features/support will get loaded (and therefore not even Rails gets loaded, and none of stuff under app)

Move all your feature files to features/*feature and you should be fine.

See --help for --require for details.

HTH,
Aslak
 

If you have a recent setup of cucumber you should have a "cucumber" environment that uses the same db as the "test" db, but that sounds unrelated to your problem.
 


Cheers,
Martins



martins

unread,
Aug 1, 2009, 6:17:24 AM8/1/09
to Cukes
On Aug 1, 11:41 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
>
> You have features under step_definitions? Only ruby files are supposed to go
> there. When you run like this, nothing under features/support will get
> loaded (and therefore not even Rails gets loaded, and none of stuff under
> app)
>
> Move all your feature files to features/*feature and you should be fine.

Yeah, that was it!
Thanks for the swift feeback! :)
Reply all
Reply to author
Forward
0 new messages