if __name__ is None
if __name__ is None

Reputation: 11533

Generate Rspec test for existing Rails 3 Model

I've decided to learn Rspec, because I like its syntax better. So I've included the rspec-rails gem and ran rails g rspec:install. I've than modified my .rspec and rspec-helper files (using mocha and factory girl).

Than, I've generated the specs file for my model using rails g rspec:model search. My model is search.rb and class name is Search.

So in my /spec/models/search_spec.rb generated by rspec:model generator, I have:

require 'spec_helper'

describe Search do
  describe "#merge_searches" do

  end
end

But when I try to run the test, I get the error:

Jans-MacBook-Pro-2:spec jan$ rspec models/search_spec.rb /Users/jan/Documents/ruby/js3/spec/models/search_spec.rb:3:in `': uninitialized constant Search (NameError)

What am I doing wrong?

Upvotes: 1

Views: 2195

Answers (1)

deivid
deivid

Reputation: 5268

I can reproduce that error if I don't have a model named Search. Once I create app/models/search.rb with content

class Search < ActiveRecord::Base
end

the error goes away. Hope it helps.

Upvotes: 1

Related Questions