Rails 2.2.2 Cucumber 0.1.15 SQLite3 I have this migration for the User model: class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| ... t.string :sms_address t.boolean :user_administrator, :default => false, :null => false t.string :username, :null => false ... I see this in the DB schema: CREATE TABLE "users" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ... "sms_address" varchar(255), "user_administrator" boolean DEFAULT ''f'' NOT NULL, "username" varchar(255) NOT NULL, ... And in the console I see this:>> myuser=User.new=> #<User id: nil, crypted_password: nil, current_login_at: nil, current_login_ip: nil, email: nil, last_login_at: nil, last_login_ip: nil, last_request_at: nil, login_count: nil, name_last: nil, name_first: nil, name_middle: nil, openid_identifier: nil, password_salt: nil, perishable_token: nil, persistence_token: nil, single_access_token: nil, sms_address: nil, user_administrator: false, username: nil, created_at: nil, updated_at: nil> ?>>> y myuser.attributes.sort--- ... - - - sms_address - - - updated_at - - - user_administrator - false - - username - => nil So, as far as I can see user_administrator is an attribute of users. However, when I have this step defintion: When /user named "(.*)" is an administrator/ do |name| my_user = User.find_by_username!(name) my_user.user_administrator end Then I see this error: And the user named "newuser" is an administrator # features/app/models/users/step_definitions/user_steps.rb:24 undefined method `user_administrator'' for #<User:0x2ac26fa83e80> (NoMethodError) /usr/lib64/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in `method_missing'' ./features/app/models/users/step_definitions/user_steps.rb:26:in `And /user named "(.*)" is an administrator/'' features/app/models/users/user.feature:29:in `And the user named "newuser" is an administrator'' Have I misspelled something somewhere and just cannot see it? what is causing this? -- Posted via http://www.ruby-forum.com/.
James Byrne wrote:> Then I see this error: > > And the user named "newuser" is an administrator # > features/app/models/users/step_definitions/user_steps.rb:24 > undefined method `user_administrator'' for #<User:0x2ac26fa83e80> > (NoMethodError) > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in > `method_missing'' > ./features/app/models/users/step_definitions/user_steps.rb:26:in > `And /user named "(.*)" is an administrator/'' > features/app/models/users/user.feature:29:in `And the user named > "newuser" is an administrator'' > > > Have I misspelled something somewhere and just cannot see it? what is > causing this?I have changed the type to string and get the same error. I have changed the attribute name to useradministrator and still get the same error. -- Posted via http://www.ruby-forum.com/.
James Byrne wrote: I have gotten past this somehow. The only thing that I think may have influenced this is manually preparing the test database. However, now I have a different problem. Here is the same step definition: When /user named "(.*)" is an administrator/ do |name| my_user = User.find_by_username!(name) puts my_user.administrator.to_s my_user.administrator end This produces this output in a cucumber run: false And the user named "newuser" is an administrator # features/app/models/users/step_definitions/user_steps.rb:24 Notice the value reported from the puts statement. Yet, this feature step passes. What am I doing wrong? -- Posted via http://www.ruby-forum.com/.
On 14 Jan 2009, at 18:46, James Byrne wrote:> Then I see this error: > > And the user named "newuser" is an administrator # > features/app/models/users/step_definitions/user_steps.rb:24 > undefined method `user_administrator'' for #<User:0x2ac26fa83e80> > (NoMethodError) > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ > active_record/attribute_methods.rb:260:in > `method_missing'' > ./features/app/models/users/step_definitions/user_steps.rb:26:in > `And /user named "(.*)" is an administrator/'' > features/app/models/users/user.feature:29:in `And the user named > "newuser" is an administrator''Try rake db:test:prepare maybe? Matt Wynne http://blog.mattwynne.net http://www.songkick.com
aslak hellesoy
2009-Jan-14 19:19 UTC
[rspec-users] Missing model attribute in cucumber test
On Wed, Jan 14, 2009 at 7:46 PM, James Byrne <lists at ruby-forum.com> wrote:> Rails 2.2.2 > Cucumber 0.1.15 > SQLite3 > > I have this migration for the User model: > > class CreateUsers < ActiveRecord::Migration > def self.up > create_table :users do |t| > ... > t.string :sms_address > t.boolean :user_administrator, :default => false, > :null => false > t.string :username, :null => false > ... > > I see this in the DB schema: > > CREATE TABLE "users" ( > "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, > ... > "sms_address" varchar(255), > "user_administrator" boolean DEFAULT ''f'' NOT NULL, > "username" varchar(255) NOT NULL, > ... > > And in the console I see this: > > >> myuser=User.new > => #<User id: nil, crypted_password: nil, current_login_at: nil, > current_login_ip: nil, email: nil, last_login_at: nil, last_login_ip: > nil, last_request_at: nil, login_count: nil, name_last: nil, name_first: > nil, name_middle: nil, openid_identifier: nil, password_salt: nil, > perishable_token: nil, persistence_token: nil, single_access_token: nil, > sms_address: nil, user_administrator: false, username: nil, created_at: > nil, updated_at: nil> > ?> > >> y myuser.attributes.sort > --- > ... > - > - - sms_address > - > - - updated_at > - > - - user_administrator > - false > - - username > - > => nil > > So, as far as I can see user_administrator is an attribute of users. > > However, when I have this step defintion: > > When /user named "(.*)" is an administrator/ do |name| > my_user = User.find_by_username!(name) > my_user.user_administrator > end > > Then I see this error: > > And the user named "newuser" is an administrator # > features/app/models/users/step_definitions/user_steps.rb:24 > undefined method `user_administrator'' for #<User:0x2ac26fa83e80> > (NoMethodError) > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in > `method_missing'' > ./features/app/models/users/step_definitions/user_steps.rb:26:in > `And /user named "(.*)" is an administrator/'' > features/app/models/users/user.feature:29:in `And the user named > "newuser" is an administrator'' > > > Have I misspelled something somewhere and just cannot see it? what is > causing this?Did you migrate your test db? rake features does that for you, but plain cucumber doesn''t Aslak> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090114/d71d8d79/attachment.html>
aslak hellesoy
2009-Jan-14 19:52 UTC
[rspec-users] Missing model attribute in cucumber test
On Wed, Jan 14, 2009 at 7:56 PM, James Byrne <lists at ruby-forum.com> wrote:> James Byrne wrote: > > > Then I see this error: > > > > And the user named "newuser" is an administrator # > > features/app/models/users/step_definitions/user_steps.rb:24 > > undefined method `user_administrator'' for #<User:0x2ac26fa83e80> > > (NoMethodError) > > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in > > `method_missing'' > > ./features/app/models/users/step_definitions/user_steps.rb:26:in > > `And /user named "(.*)" is an administrator/'' > > features/app/models/users/user.feature:29:in `And the user named > > "newuser" is an administrator'' > > > > > > Have I misspelled something somewhere and just cannot see it? what is > > causing this? > > I have changed the type to string and get the same error. I have > changed the attribute name to useradministrator and still get the same > error.Some things you can try * Open a raw database session against the test db and look at tables and columns * script/runner "p User.column_names" -e test * script/runner "p User.column_names" -e development> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090114/fe50df64/attachment-0001.html>
Fernando García Samblas
2009-Jan-14 20:54 UTC
[rspec-users] Missing model attribute in cucumber test
James Byrne escribi?:> James Byrne wrote: > > I have gotten past this somehow. The only thing that I think may have > influenced this is manually preparing the test database. However, now I > have a different problem. > > Here is the same step definition: > > When /user named "(.*)" is an administrator/ do |name| > my_user = User.find_by_username!(name) > puts my_user.administrator.to_s > my_user.administrator > end >I think the last statement of the step definition "should be": my_user.administrator.should be_true for an rspec based implementation, or fail unless my_user.administrator for a pure cucumber one.> This produces this output in a cucumber run: > > false > And the user named "newuser" is an administrator # > features/app/models/users/step_definitions/user_steps.rb:24 > > Notice the value reported from the puts statement. Yet, this feature > step passes. What am I doing wrong? >-- Fernando Garc?a Samblas fernando.garcia at the-cocktail.com http://nando.lacoctelera.com The Cocktail C/ Salamanca 17 28020 Madrid +34 91 567 06 05
Aslak Hellesøy
2009-Jan-14 21:05 UTC
[rspec-users] Missing model attribute in cucumber test
> James Byrne wrote: > > I have gotten past this somehow. The only thing that I think may have > influenced this is manually preparing the test database. However, > now I > have a different problem. > > Here is the same step definition: > > When /user named "(.*)" is an administrator/ do |name| > my_user = User.find_by_username!(name) > puts my_user.administrator.to_s > my_user.administrator > end > > This produces this output in a cucumber run: > > false > And the user named "newuser" is an administrator # > features/app/models/users/step_definitions/user_steps.rb:24 > > Notice the value reported from the puts statement. Yet, this feature > step passes. What am I doing wrong?Where did you expect it to fail? This will fail: my_user.should be_administrator False return values never fails unless you use #should like above. Aslak> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users