I am writing Rspec tests for my models in a Ruby on Rails application. And I get this error when running the 'rspec spec'
command: /spec/models/client_spec.rb:4:in `<top (required)>': uninitialized constant Client (NameError)
I am using Rails 4.0.0 and Ruby 2.0.0
Here is my client_spec.rb:
require 'spec_helper' describe Client do it 'is invalid without first_name', :focus => true do client = Client.new client.should_not be_valid end end
And gemfile:
source 'https://rubygems.org'
And finally .rb client (model and class ROR):
class Client < ActiveRecord::Base has_many :cars has_many :orders has_one :client_status has_one :discount_plan, through: :client_status validates :email, format: { with: /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[az]{2,4})\z/, :message => "Only emails allowed", :multiline => true } validates :email, presence: true, if: "phone.nil?" #validates :phone, presence: true, if: "email.nil?" validates :last_name, :first_name, presence: true validates :last_name, :first_name, length: { minimum: 2, maximum: 500, wrong_length: "Invalid length", too_long: "%{count} characters is the maximum allowed", too_short: "must have at least %{count} characters" } end
If it were useful for my spec_helper.rb file:
# This file was generated by the `rspec --init` command. Conventionally, all
ruby-on-rails testing model rspec
Stan Jul 6 '13 at 21:43 2013-07-06 21:43
source share