I installed the Rspec gem but I can’t install the RSpec On Rails
plugin (the url is not goood).
the URL for the RSpec On Rails plugin is not good so I can’t
install it.
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.
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.
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
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:
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”) @user.username = ‘someusername’ @user.should be_valid
end
after do @user = nil
end
end
################################################################