[rspec-users] How to spec a model method

David Parker nemo7467 at gmail.com
Fri Aug 10 19:18:34 EDT 2007


Still new to Specs...
How do I create a spec to test a model method?  Specifically, here is my
spec:
#testing model
describe User do
  it "should have many user roles" do
    User.reflect_on_association(:user_roles).should_not be_nil
  end

  it "should have many roles though user roles" do
    User.reflect_on_association(:roles).should_not be_nil
  end

  it "should know what role it has" do
    #User.should
  end
end

The last spec is incomplete... basically, I will want the code to be
something like this:
class User < ActiveRecord::Base
    has_many :user_roles
    has_many :roles, :through => :user_roles

    def has_role?(role)
      self.roles.count(:conditions => ['name = ?', role]) > 0
    end
end

How would I spec the last method?
Thanks
-- 
dp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070810/f4587f0e/attachment.html 


More information about the rspec-users mailing list