[rspec-users] newbie cucumber tutorial

Sarah Allen lists at ruby-forum.com
Mon Dec 22 14:09:19 EST 2008

I realize this is off-topic for the RSpec forum and cucumber tutorial, 
but I'm hoping you'll enlighten me on this point which is, I guess, more 
of a Ruby language question...

Aslak Hellesøy wrote:
>> As you can see from my series of blog posts, I'm
>> new to Ruby and Rails.  I thought that ending a method with ! was a
>> naming convention.  Reading the humble ruby book it says "Another
>> convention to follow is that if the method modifies its receiver in
>> place (i.e. the method modifies the object that called it), then it
>> should end in an exclamation point" and the Rails doc show examples of
>> create without !
>> http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001969 but if
>> I make the change you suggest the test passes.  I've updated the
>> tutorial and my code, but I'm confused.
> The #create! method is documented here:
> http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001902
> Essentially, #create will never raise an error no matter what you pass 
> it,
> and you actually want exceptions for bad input in your tests (step
> definitions).
> Therefore - use #create! (or #save!). In your app, use the non-bang 
> methods.

My Task model is simply defined (by the generate scaffold script) as:
class Task < ActiveRecord::Base

How is it that I can call Task.create! which is a method of 
ActiveRecord::Validations ?

Thanks in advance,

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list