Rspec tutorial

I am trying to follow this tutorial - http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1

I installed the Rspec gem but I can't install the RSpec On Rails plugin (the url is not goood).

1. the URL for the RSpec On Rails plugin is not good so I can't install it. 2. What is the usage of this plugin? I think that it let me generate Rspec files like this: script/generate rspec_model User but I am not sure.

3. What is the different between a gem and a plugin? here is my guess: a gem is global to my machine and a plugin is added to a specific project. a plugin adds a generator to my project.

See http://rspec.rubyforge.org/documentation/rails/install.html for current information.

great. it works. now i am facing this problem- I get this error when running Rspec- NoMethodError in 'A user (in general) should be invalid without a username' undefined method `should_not_be_valid' for #<User:0xb6fdbd4c> ./spec/models/user_spec.rb:9:

#the model - user.rb class User < ActiveRecord::Base   validates_presence_of :username end

#the migration file - 001_create_users.rb this is my migration file: class CreateUsers < ActiveRecord::Migration   def self.up     create_table :users do |t|       t.column :first_name, :string       t.column :last_name, :string       t.column :email, :string       t.column :description, :string       t.column :username, :string       t.column :encrypted_password, :string       t.column :salt, :string     end   end

  def self.down     drop_table :users   end end

#the rpec file - user_spec.rb require File.dirname(__FILE__) + '/../spec_helper'

context "A user (in general)" do   setup do     @user = User.new   end

  specify "should be invalid without a username" do     @user.should_not_be_valid   end end

great. it works. now i am facing this problem- I get this error when running Rspec- NoMethodError in 'A user (in general) should be invalid without a username' undefined method `should_not_be_valid' for #<User:0xb6fdbd4c> ./spec/models/user_spec.rb:9:

You must reading some old docs. Try this:

user.should_not be_valid

(no _ between not and be)

thanks David, it works. and I also found a nice notification popup for my ubuntu: http://snakesgemscoffee.blogspot.com/2007/07/marrying-autotest-with-rspec-on-gnome.html

David Chelimsky wrote: >> >> great. it works. >> now i am facing this problem- >> I get this error when running Rspec- >> NoMethodError in 'A user (in general) should be invalid without a >> username' >> undefined method `should_not_be_valid' for #<User:0xb6fdbd4c> >> ./spec/models/user_spec.rb:9: > > You must reading some old docs. Try this: > > user.should_not be_valid > > (no _ between not and be)

David, I'm working through the same tutorial and can't get part of the spec to fail. There's probably a simple explanation for it, but it doesn't make much sense to me at the moment. I tried changing the error message checked for and it had not affect. It should have failed. Here's the code:

################################################################ class User < ActiveRecord::Base   validates_presence_of :username , :message => "is required" end ################################################################ require File.dirname(__FILE__) + '/../spec_helper'

describe User do   before do     @user = User.new   end

  it "should be invalid without a username" do     @user.should_not be_valid     @user.errors.on(:username).should equal?("is _this_should_fail_ required")

Get rid of the question mark:

@user.errors.on(:username).should equal("is _this_should_fail_required")

Also - keep in mind that rspec has 3 equality matchers:

equal(expected) eql(expected) == expected

Each one works like the corresponding ruby method. So ...

"this".should equal("this")

will fail, because "this".equal?("this") would fail.