I am using rails edge. I am using gem "rspec-rails", "= 2.0.0.beta. 19" . I have following code at spec/models/user_spec.rb require ''spec_helper'' describe User do it { should validate_presence_of(:email) } it { should validate_presence_of(:name) } end Here is my gemfile group :development, :test do gem ''factory_girl_rails'', :git => ''git://github.com/thoughtbot/ factory_girl_rails'' gem ''shoulda'' gem "rspec-rails", "= 2.0.0.beta.19" gem "cucumber-rails", "= 0.3.2" gem "capybara" gem "launchy" end I am getting following error message. Failure/Error: it { should validate_presence_of(:email) } undefined method `validate_presence_of'' for #<RSpec::Core::ExampleGroup::Nested_2:0x10a63e3a8 @__memoized={}> # ./spec/models/user_spec.rb:5
On Aug 11, 2010, at 2:31 AM, Nadal wrote:> I am using rails edge. I am using gem "rspec-rails", "= 2.0.0.beta. > 19" . > > I have following code at spec/models/user_spec.rb > > require ''spec_helper'' > > describe User do > > it { should validate_presence_of(:email) } > > it { should validate_presence_of(:name) } > > end > > > Here is my gemfile > > group :development, :test do > gem ''factory_girl_rails'', :git => ''git://github.com/thoughtbot/ > factory_girl_rails'' > gem ''shoulda'' > gem "rspec-rails", "= 2.0.0.beta.19" > gem "cucumber-rails", "= 0.3.2" > gem "capybara" > gem "launchy" > end > > I am getting following error message. > > > Failure/Error: it { should validate_presence_of(:email) } > undefined method `validate_presence_of'' for > #<RSpec::Core::ExampleGroup::Nested_2:0x10a63e3a8 @__memoized={}> > # ./spec/models/user_spec.rb:5Sounds like shoulda is not registering itself properly with rspec-2. I''d check with the should list: http://groups.google.com/group/shoulda. HTH, David
On Aug 11, 2010, at 9:36 AM, David Chelimsky wrote:> > On Aug 11, 2010, at 2:31 AM, Nadal wrote: > >> I am using rails edge. I am using gem "rspec-rails", "= 2.0.0.beta. >> 19" . >> >> I have following code at spec/models/user_spec.rb >> >> require ''spec_helper'' >> >> describe User do >> >> it { should validate_presence_of(:email) } >> >> it { should validate_presence_of(:name) } >> >> end >> >> >> Here is my gemfile >> >> group :development, :test do >> gem ''factory_girl_rails'', :git => ''git://github.com/thoughtbot/ >> factory_girl_rails'' >> gem ''shoulda'' >> gem "rspec-rails", "= 2.0.0.beta.19" >> gem "cucumber-rails", "= 0.3.2" >> gem "capybara" >> gem "launchy" >> end >> >> I am getting following error message. >> >> >> Failure/Error: it { should validate_presence_of(:email) } >> undefined method `validate_presence_of'' for >> #<RSpec::Core::ExampleGroup::Nested_2:0x10a63e3a8 @__memoized={}> >> # ./spec/models/user_spec.rb:5 > > Sounds like shoulda is not registering itself properly with rspec-2. I''d check with the should list: http://groups.google.com/group/shoulda.Also - the subject line is backwards - it shoulda been "shoulda not working with rspec-2" ;)> > HTH, > David > > >
On Wed, Aug 11, 2010 at 10:38 AM, David Chelimsky <dchelimsky at gmail.com>wrote:> > Also - the subject line is backwards - it shoulda been "shoulda not working > with rspec-2" ;)It''s been a long time since I tried shoulda, but I used to like to give the advice, "you shoulda used RSpec instead." ;-) Hope you get everything working, Nadal. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100811/c65568e1/attachment.html>
I posted a question on shoulda forum. It is under moderation so I don''t have a link yet. To the people who do not use shoulda: How would you write a test for above case. I assume it would require set up a subject, set nil value, and then see if there is an error message. I still think that for such cases should macro is succint and does it job well unless I am missing some new feature of rspec2. Thanks On Aug 11, 12:28?pm, Craig Demyanovich <cdemyanov... at gmail.com> wrote:> On Wed, Aug 11, 2010 at 10:38 AM, David Chelimsky <dchelim... at gmail.com>wrote: > > > > > Also - the subject line is backwards - it shoulda been "shoulda not working > > with rspec-2" ;) > > It''s been a long time since I tried shoulda, but I used to like to give the > advice, "you shoulda used RSpec instead." ;-) > > Hope you get everything working, Nadal. > > Regards, > Craig > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
On Wed, Aug 11, 2010 at 12:53 PM, Nadal <node.js99 at gmail.com> wrote:> I posted a question on shoulda forum. It is under moderation so I > don''t have a link yet. > > To the people who do not use shoulda: How would you write a test for > above case. I assume it would require set up a subject, set nil value, > and then see if there is an error message. I still think that for such > cases should macro is succint and does it job well unless I am missing > some new feature of rspec2.I don''t yet use RSpec 2, but I don''t think you''re missing anything. Shoulda may very well be a good fit for these kinds of examples. Since you asked, here''s how I currently write examples like the ones you posted. require ''spec_helper'' describe User, "being valid" do it "requires an email" do user = User.new(:email => nil) user.should_not be_valid user.should have(1).error_on(:email) end it "requires a name" do user = User.new(:name => nil) user.should_not be_valid user.should have(1).error_on(:name) end end Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100811/a290f4a7/attachment.html>
On 2010-08-11 12:29 PM, Craig Demyanovich wrote:> On Wed, Aug 11, 2010 at 12:53 PM, Nadal <node.js99 at gmail.com > <mailto:node.js99 at gmail.com>> wrote: > > I posted a question on shoulda forum. It is under moderation so I > don''t have a link yet. > > To the people who do not use shoulda: How would you write a test for > above case. I assume it would require set up a subject, set nil value, > and then see if there is an error message. I still think that for such > cases should macro is succint and does it job well unless I am missing > some new feature of rspec2. > > > I don''t yet use RSpec 2, but I don''t think you''re missing anything. > Shoulda may very well be a good fit for these kinds of examples. > > Since you asked, here''s how I currently write examples like the ones > you posted. > > require ''spec_helper'' > > describe User, "being valid" do > it "requires an email" do > user = User.new(:email => nil) > user.should_not be_valid > user.should have(1).error_on(:email) > end > it "requires a name" do > user = User.new(:name => nil) > user.should_not be_valid > user.should have(1).error_on(:name) > end > end > > Regards, > CraigThat''s exactly what I used to do, also, until I switched to Remarkable. Now it''s: before :each do @user = User.create(valid_user_hash) end should_validate_presence_of :first_name should_validate_presence_of :last_name should_validate_presence_of :email should_validate_uniqueness_of :email, :case_sensitive => false should_validate_format_of_email One thing I have come to appreciate about this is being able to copy the should_* statements to my model and, using TextMate''s column editing mode, remove the ''should_'' and add an ''s'' at the end of ''validate'' and I''m done. For all of the validations that Remarkable supports, the same options are supported as well. That''s actually why I switch from Shoulda to Remarkable a year or so ago (things might have changed in Shoulda by now, though): Not all validation options were supported in Shoulda. Peace, Phillip