Am I on the right track

111 views
Skip to first unread message

roelof

unread,
Nov 2, 2012, 11:44:28 AM11/2/12
to cu...@googlegroups.com
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

aslak hellesoy

unread,
Nov 2, 2012, 1:19:55 PM11/2/12
to Cucumber Users
On Fri, Nov 2, 2012 at 3:44 PM, roelof <rwo...@hotmail.com> wrote:
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 :



The comment in snippets is there for a reason (pending # express the regexp above with the code you wish you had)

Instead of leaving the Given stepdef blank you should have written some code here. Since you didn't you got confused at a later stage - in the When step.
 
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
 
 

roelof

unread,
Nov 2, 2012, 2:30:53 PM11/2/12
to cu...@googlegroups.com

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.

Roelof

Op vrijdag 2 november 2012 18:20:18 UTC+1 schreef Aslak Hellesøy het volgende:

George Dinwiddie

unread,
Nov 2, 2012, 3:21:53 PM11/2/12
to cu...@googlegroups.com
Roelof,

On 11/2/12 2:30 PM, roelof wrote:
> 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.

You have never initialized the @user variable. Since it's nil, you can't
call any methods on it.

- George

P.S. Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

>
> Roelof
>
> Op vrijdag 2 november 2012 18:20:18 UTC+1 schreef Aslak Hellesøy het
> volgende:
>
>
>
>
> On Fri, Nov 2, 2012 at 3:44 PM, roelof <rwo...@hotmail.com
> <javascript:>> wrote:
>
> Hello,
>
> I making my first BDD site which you can find here :
> https://github.com/roelof1967/tamara
> <https://github.com/roelof1967/tamara>
> Now the first test is failing with this message :
>
>
> See https://github.com/roelof1967/tamara/pull/1
> <https://github.com/roelof1967/tamara/pull/1>
>
> The comment in snippets is there for a reason (pending# express the
> regexp above with the code you wish you had)
>
> Instead of leaving the Given stepdef blank you should have written
> some code here. Since you didn't you got confused at a later stage -
> in the When step.
>
> 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 <http://user.name> or do I
> don't see the right reason ?
>
> Roelof

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

roelof

unread,
Nov 3, 2012, 4:09:27 AM11/3/12
to cu...@googlegroups.com
Thanks,

I now get this message:

Scenario: log in as existing user     # features/login.feature:3
    Given a user "Aslak" exists         # features/step_definitions/login_steps.rb:5
      unknown attribute: name (ActiveRecord::UnknownAttributeError)
      ./features/step_definitions/login_steps.rb:6:in `/^a user "(.*?)" exists$/'
      features/login.feature:4:in `Given a user "Aslak" exists'

Must I now write my spec files or must I change something in my step-defenitions to solve this problem.

Roelof


Op vrijdag 2 november 2012 20:21:58 UTC+1 schreef George Dinwiddie het volgende:

roelof

unread,
Nov 3, 2012, 5:07:18 AM11/3/12
to cu...@googlegroups.com
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



Op zaterdag 3 november 2012 09:09:27 UTC+1 schreef roelof het volgende:

Vicenzo Naves

unread,
Nov 3, 2012, 7:05:28 AM11/3/12
to cu...@googlegroups.com


Vicenzo Naves

Sent from my iPhone
+55 (31)9996-6915

On 03/11/2012, at 07:07, roelof <rwo...@hotmail.com> wrote:

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?
You are trying to reach a record with 2 arguments where you dont need any.

Roelof Wobben

unread,
Nov 3, 2012, 7:24:20 AM11/3/12
to cu...@googlegroups.com

 Hello,
 
My steps definition looks like this :
 
 
 

Subject: Re: [Cucumber] Am I on the right track
From: vic...@gmail.com
Date: Sat, 3 Nov 2012 09:05:28 -0200
To: cu...@googlegroups.com




Vicenzo Naves

Sent from my iPhone
+55 (31)9996-6915

On 03/11/2012, at 07:07, roelof <rwo...@hotmail.com> wrote:

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?
You are trying to reach a record with 2 arguments where you dont need any.
 
It's look like this :
 
class User < ActiveRecord::Base
attr_accessible :name, :password
def initialize
@name = name
@password = password
end
end

Given /^a user "(.*?)" exists$/ do |user_name|
@user = User.create!(:name => user_name, :password => "s3cr3t")
end

When /^he logs in$/ do
visit("/users/sign_in")
fill_in('User name', :with => @user.name)
fill_in('Password', :with => @user.password)
click_button('Log in')
end

Then /^he should see "(.*?)"$/ do
pending # express the regexp above with the code you wish you had
end

When /^he logs in with a bad password$/ do
pending # express the regexp above with the code you wish you had
end

Then /^he should not see "(.*?)"$/ do |arg1|
pending # express the regexp above with the code you wish you had
end
 
 
Roelof

Vicenzo Naves

unread,
Nov 3, 2012, 7:28:54 AM11/3/12
to cu...@googlegroups.com
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 create
  User.new(:params)
end

something like that...

Vicenzo Naves
ISTQB CTFL Certified
Analista de Testes
(31) 9996-6915
www.geekcuisine.com.br

aslak hellesoy

unread,
Nov 3, 2012, 7:39:03 AM11/3/12
to Cucumber Users
On Sat, Nov 3, 2012 at 9:07 AM, roelof <rwo...@hotmail.com> wrote:
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


May I suggest you study Ruby on Rails before you continue any further? This is not how you create attributes on an activerecord class. It's done by adding columns to its table. You have to add a migration.

It seems like you're new to more than just Cucumber, and that makes it a little tricky to use a forum like this. We want to stay focussed on Cucumber here.

Aslak

roelof

unread,
Nov 3, 2012, 8:57:40 AM11/3/12
to cu...@googlegroups.com
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

      undefined method `[]' for nil:NilClass (NoMethodError)
      ./features/step_definitions/login_steps.rb:6:in `/^he logs in$/'

      features/login.feature:5:in `When he logs in'


I changed the scenario because the devise gem is using a email adress instead of a name.
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.

Roelof


Op zaterdag 3 november 2012 12:39:28 UTC+1 schreef Aslak Hellesøy het volgende:

aslak hellesoy

unread,
Nov 3, 2012, 9:09:17 AM11/3/12
to Cucumber Users
On Sat, Nov 3, 2012 at 12:57 PM, roelof <rwo...@hotmail.com> wrote:
Your right.
Im new to Cucumber and Ruby. I tought I had learned Ruby from codeschool but appearently I don know enough


Ruby (the programming language) is not the same as Ruby on Rails (the web framework written in Ruby).
 
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

      undefined method `[]' for nil:NilClass (NoMethodError)
      ./features/step_definitions/login_steps.rb:6:in `/^he logs in$/'

      features/login.feature:5:in `When he logs in'


I changed the scenario because the devise gem is using a email adress instead of a name.
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.


Rails is a pretty big framework and I'd definitely pick up a book teaching it. Some Rails books might try to teach you Ruby as well, but it might be useful to pick up a (non-Rails) Ruby book as well.

And of course - the Cucumber book!

Aslak

roelof

unread,
Nov 16, 2012, 2:33:42 AM11/16/12
to cu...@googlegroups.com
Hello Aslak,

Everything is working. See this git repo : https://github.com/roelof1967/tamara

Roelof


Op vrijdag 2 november 2012 16:44:28 UTC+1 schreef roelof het volgende:
Reply all
Reply to author
Forward
0 new messages