Hello,
I making my first BDD site which you can find here : https://github.com/roelof1967/tamara
Now the first test is failing with this message :
Given a user "Aslak" exists # features/step_definitions/login_steps.rb:1
When he logs in # features/step_definitions/login_steps.rb:4
undefined method `[]' for nil:NilClass (NoMethodError)
./features/step_definitions/login_steps.rb:5:in `/^he logs in$/'
features/login.feature:5:in `When he logs in'
Is this because I use @user.name or do I don't see the right reason ?
Roelof
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
One thing I don't understand. Why create a new user ?
In my opinion a existing user is a user which is already in the database and in the user model so a existing user is already created.
I solved this one with chancing the class definition to this :
class User < ActiveRecord::Base
attr_accessible :name, :password
def initialize
@name = name
@password = password
end
end
But now I see this message:
Given a user "Aslak" exists # features/step_definitions/login_steps.rb:10
wrong number of arguments (2 for 0) (ArgumentError)
./features/step_definitions/login_steps.rb:4:in `initialize'
./features/step_definitions/login_steps.rb:11:in `/^a user "(.*?)" exists$/'
features/login.feature:4:in `Given a user "Aslak" exists'
Roelof
How your step def looks like?I solved this one with chancing the class definition to this :
class User < ActiveRecord::Base
attr_accessible :name, :password
def initialize
@name = name
@password = password
end
end
But now I see this message:
Given a user "Aslak" exists # features/step_definitions/login_steps.rb:10
wrong number of arguments (2 for 0) (ArgumentError)
./features/step_definitions/login_steps.rb:4:in `initialize'
./features/step_definitions/login_steps.rb:11:in `/^a user "(.*?)" exists$/'
features/login.feature:4:in `Given a user "Aslak" exists'
Roelof
It's look like this :
class User < ActiveRecord::Baseattr_accessible :name, :passworddef initialize@name = name@password = passwordendend
Given /^a user "(.*?)" exists$/ do |user_name|@user = User.create!(:name => user_name, :password => "s3cr3t")endWhen /^he logs in$/ dovisit("/users/sign_in")fill_in('User name', :with => @user.name)fill_in('Password', :with => @user.password)click_button('Log in')endThen /^he should see "(.*?)"$/ dopending # express the regexp above with the code you wish you hadendWhen /^he logs in with a bad password$/ dopending # express the regexp above with the code you wish you hadendThen /^he should not see "(.*?)"$/ do |arg1|pending # express the regexp above with the code you wish you hadendRoelof
Then the problem is with the model.I believe you are using RoR.The model is created with scaffolding, they have the basic for what you want.The thing is, you have to have the controller for be able to access it.def createUser.new(:params)endsomething like that...
I solved this one with chancing the class definition to this :
class User < ActiveRecord::Base
attr_accessible :name, :password
def initialize
@name = name
@password = password
end
end
Your right.
Im new to Cucumber and Ruby. I tought I had learned Ruby from codeschool but appearently I don know enough
I was just asking about a new problem but maybe I can better ask on the Ruby Forum,
I now see these messages :
When he logs in # features/step_definitions/login_steps.rb:5./features/step_definitions/login_steps.rb:6:in `/^he logs in$/'
undefined method `[]' for nil:NilClass (NoMethodError)I changed the scenario because the devise gem is using a email adress instead of a name.
features/login.feature:5:in `When he logs in'
But appearently I missed something.
II wonder if this is too hard material to learn without a teacher and learn this from a book myself.