RSpec not finding my named routes - ruby-on-rails

I'm having an inexplicably hard time getting my named routes to work within my rspec tests.
Here's what I'm seeing:
1) Home GET / works!
Failure/Error: get root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe13b0c1538>
# ./spec/requests/home_spec.rb:6:in `block (3 levels) in <top (required)>'
2) Home GET / shows products!
Failure/Error: get products_path
NameError:
undefined local variable or method `products_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe13b0cdea0>
# ./spec/requests/home_spec.rb:10:in `block (3 levels) in <top (required)>'
spec/requests/home_spec.rb
require 'spec_helper'
describe "Home" do
describe "GET /" do
it "works!" do
get root_path
response.status.should be(200)
end
it "shows products!" do
get products_path
response.status.should be(200)
end
end
end
spec/spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
require 'spree/core/testing_support/factories'
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.before(:suite) do
# DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
# DatabaseCleaner.start
end
config.after(:each) do
# DatabaseCleaner.clean
end
config.include Rails.application.routes.url_helpers
end
You can see that the test is including spec_helper, and spec_helper is including the routing methods. Here's my rake routes:
bundle exec rake routes
...
root / spree/home#index
products GET /products(.:format) spree/products#index
...
Any idea what could be going on here to prevent the routes from working? Thanks!

If you're wanting to reference the route of an engine from tests within an dummy application, or just an application itself, then you'll need to prefix the routing helpers with the engine name. For Spree, you would reference the routes like:
spree.products_path
Similarly, if you want to reference routes of the main application from an engine, you'll need to use main_app:
main_app.root_path

Related

rspec not loading factory

I am just getting started on rspec, and I may have included to much in the first go. I followed this guide but cant seem to get it all to come together.
I have a Model called Photo, so I have created a Factory girl for that:
# spec/factories/photo.rb
FactoryGirl.define do
factory :photo do
date_taken { Faker::Date.backward(14) }
end
end
I use this in a test:
#spec/models/photo_spec.rb
require 'rails_helper'
RSpec.describe Photo, type: :model do
it "has a valid factory" do
expect(photo).to be_valid
end
end
But I get the following, indicating that the photo factory is not loaded...
rspec spec/models/photo_spec.rb
Failures:
1) Photo has a valid factory
Failure/Error: expect(photo).to be_valid
NameError:
undefined local variable or method `photo' for #<RSpec::ExampleGroups::Photo:0x00000004b769f8>
# ./spec/models/photo_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.29491 seconds (files took 7.67 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/models/photo_spec.rb:4 # Photo has a valid factory
My config is:
#spec/rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'shoulda/matchers'
require 'database_cleaner'
require 'support/factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
in support dir:
#spec/support/factory_girl.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
#spec/support/database_cleaner.rb`enter code here`
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Down in the comments section on the linked guide, there's a comment by Rhys Davis on 11 Jan 2016
Although in the Model Specs section I had to add the following to
rails_helper.rb: config.include FactoryGirl::Syntax::Methods
then also add the following to my contact_spec.rb: contact =
build(:contact)
and then a reply by Arkadiusz Zdanowski on 5 Sep
Yes, without those lines I got the following error:
Failures:
1) Contact has a valid factory
Failure/Error: expect(contact).to be_valid
NameError:
undefined local variable or method `contact' for #
Which is the same error you're getting now, so adding those 2 lines should probably fix the issue for you.

Rspec undefined local variable or method root_path

I'm starting to use Rspec, but when I run bundle exec rspec I get an error
/spec/requests/pages_spec.rb:20:in `block (2 levels) in <top (required)>': undefined local
variable or method `root_path' for #<Class:0x00000102e46850> (NameError)
I do not have Spork or Guard running so the question below shouldn't apply
undefined local variable or method `root_path' (Rspec Spork Guard)
I have added config.include Rails.application.routes.url_helpers in my spec_helper.rb file, but that did not help.
undefined local variable or method `root_path' Hartl's Tutorial Chapter 5.3.2
Here's pages_spec.rb
require 'spec_helper'
describe "Pages" do
describe "navigation" do
def self.it_should_be_on(path_name, value=nil)
before { visit path_name }
it "should be on #{path_name}" do
page.should have_link('Home')
page.should have_link('Inventory')
page.should have_link('FAQ')
page.should have_link('About Us')
page.should have_link('Location')
page.should have_link('Contact Us')
# page.should have_link('Login')
end
end
it_should_be_on root_path
it_should_be_on faq_path
it_should_be_on about_path
it_should_be_on location_path
it_should_be_on contact_path
# it_should_be_on login_path
end
end
spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include Capybara::DSL
config.include Rails.application.routes.url_helpers
end
Update
After reading about shared_examples, I tried this out successfully. Is there a better way to write this test? I ended up separating out the pages into individual pages like Home page etc.
require 'spec_helper'
describe "Pages" do
subject { page }
shared_examples "navigation" do |path_name|
before { visit send( path_name) }
describe "navigation links should be on #{path_name}" do
it { should have_link('Home') }
it { should have_link('Inventory') }
it { should have_link('FAQ') }
it { should have_link('About Us') }
it { should have_link('Location') }
it { should have_link('Contact Us') }
# it { should have_link('Login') }
end
end
describe "Home Page" do
include_examples "navigation", :root_path
end
end
None of the Rails helpers are available at the top level of RSpec's describe block. They are only available within the lower level blocks (e.g. let, before, it, etc.).
If you want to share code such as this across examples, you can use a shared_context or a shared_example, as described in the RSpec documentation, or switch to using symbols as parameters while at the describe level and defer interpretation of them as methods until you're within the lower level blocks, as shown in the answer from #IharDrozdov.
To save your structure - you can change the code like this:
require 'spec_helper'
describe "Pages" do
describe "navigation" do
shared_examples_for 'main page' do |path_name|
before { visit send(path_name) }
it "should be on #{path_name}" do
page.should have_link('Home')
page.should have_link('Inventory')
page.should have_link('FAQ')
page.should have_link('About Us')
page.should have_link('Location')
page.should have_link('Contact Us')
# page.should have_link('Login')
end
end
it_should_behave_like 'main_page', :root_path
it_should_behave_like 'main_page', :faq_path
it_should_behave_like 'main_page', :about_path
it_should_behave_like 'main_page', :location_path
it_should_behave_like 'main_page', :contact_path
# it_should_behave_like 'main_page', :login_path
end
end
because "paths are not defined at the class level in specs"(c)
You cannot call path methods in spec class. It should be in it block.
And your structure is not perfect. It will be better to put code in modules and then include it, if you want to avoid the duplication.

Undefined method "contain" for controller spec

It's definitely best to divide specs up so you have specs pertaining to each aspect of the MVC architecture, but I think there is a slight crossover with controller specs and view specs.
With view specs, you should only be concerned with the view, but with controller specs I still think it would be a good idea to test that the correct view is rendered, and maybe even test the content of the view, although more in-depth testing of the content should take place in the view spec.
Despite this clear article, https://www.relishapp.com/rspec/rspec-rails/v/2-1/docs/controller-specs/render-views, describing how to do this, I just cannot integrate my view and controller specs.
I keep getting the error undefined method 'contain'!
Here's my spec_helper:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require 'factory_girl_rails'
require 'ap'
def set(factory)
#user = FactoryGirl.create(factory)
end
def sign_up(first_name, last_name, profile_name, email, password)
visit "/"
click_link "Register"
fill_in('First name', with: first_name)
fill_in('Last name', with: last_name)
fill_in('Profile name', with: profile_name)
fill_in('Email', with: email)
fill_in('Password', with: password)
fill_in('Password confirmation', with: password)
click_button 'Sign up'
end
def sign_in(email, password)
visit "/"
click_link "Sign In"
fill_in('Email', with: email)
fill_in('Password', with: password)
click_button 'Sign in'
end
def sign_out
visit "/"
click_link "Sign Out"
end
#Webrat.configure do |config|
# config.mode = :rails
#end
#webrat
require 'capybara/poltergeist'
# Capybara.javascript_driver = :poltergeist
Capybara.javascript_driver = :selenium
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# true means 'yes, filter these specs'
config.filter_run_excluding stress: true
# config.current_driver = :webkit
# config.use_transactional_fixtures = false
# config.include Capybara::DSL
DatabaseCleaner.strategy = :truncation
config.after(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
# config.before(:suite) do
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
# DatabaseCleaner.start
# end
# config.after(:each) do
# DatabaseCleaner.clean
# end
#config.after(:suite) do
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
# DatabaseCleaner.clean
# end
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# config.include RSpec::Rails::RequestExampleGroup, type: :feature
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
I18n.enforce_available_locales = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
Here's my controller spec:
require "spec_helper"
describe UserFriendshipsController, type: :controller do
render_views
let (:user_1) { FactoryGirl.create(:user_1)}
before {
sign_in user_1
get :index
}
it "renders the :index view" do
response.should render_template(:index)
end
it "view contains expected html" do
# a sanity test more than anything
response.should contain("Welcome to the home page")
end
end
Upon running this spec I get this:
.F
Failures:
1) UserFriendshipsController view contains expected html
Failure/Error: response.should contain("Listing widgets")
NoMethodError:
undefined method `contain' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000008632268>
# ./spec/controllers/user_friendships_spec.rb:18:in `block (2 levels) in <top (required)>'
Finished in 0.1835 seconds
2 examples, 1 failure
Why is this happening? How can I get this to work?
If you look at the relish documentation for the current 2.14 version of Rspec you'll see that they're using match now instead:
expect(response.body).to match /Listing widgets/m
Using the should syntax, this should work:
response.body.should match(/Welcome to the home page/)
Right, it was a very unclear article from Rspec that caused this error. It was using webrat in its example and didn't think to tell you. If anyone else gets here, you can add webrat to your gemfile to use the contain method:
Gemfile
group :test do
gem 'webrat'
end
However, it makes a lot more sense to use rspec's native match method:
expect(response.body).to match /Listing widgets/m

Rspec and named routes

I'm quite new to rails, and trying to follow the railstutorial. Everything goes fine, except for my tests which can't get past the named routes (5.3.3)
My routes.rb :
SampleApp::Application.routes.draw do
resources :users
match '/signup', to: 'users#new'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'pages#contact'
root to: 'static_pages#home'
#Commented stuff
My firsts tests (spec/controllers/static_pages_controller_spec.rb) :
describe "Static pages" do
subject { page }
shared_examples_for "all static pages" do
it { should have_selector('h1', text: heading) }
it { should have_selector('title', text: full_title(page_title)) }
end
describe "Home page" do
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { 'Home' }
it_should_behave_like "all static pages"
end
#Other tests
The spec_helper.rb looks like (without all the commented stuff)
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
end
The errors I get from rspec are all like this one :
Static pages Home page it should behave like all static pages
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1::Nested_1:0x00000004a12210>
Shared Example Group: "all static pages" called from ./spec/controllers/static_pages_controller_spec.rb:17
# ./spec/controllers/static_pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
I already tried using
include Rails.application.routes.url_helpers
in the spec_helper, but it changed my errors to
Static pages Home page it should behave like all static pages
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
# /usr/lib/ruby/1.9.1/forwardable.rb:185
I also tried different way of renaming my routes, but none of them worked. I'm back to the tutorial version.
If it can be of any help in finding what exactly is a problem, I'm on Ubuntu 11.10, with rails 3.2.1 and ruby 1.9.2p290. Hope you can help, I spend quite a while googling for a solution and didn't find any ^^'
Named routes should work if you put the following in rspec_helper.rb:
RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
...
end
Is that how you set it up?
I don't think you have access to named routes inside of your rspec controller specs. You could however just do visit('/'), which is the equivalent of root_path.
Google brought me here, even my error message doesn't fit 100%.
In my case Capybara command visitis unknown...
Error:
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa49a73c>
Since Capybara 2.0 one has to use folder spec/features capybara commands don't work in folder spec/requests anymore.
That helped me:
http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html
Hope you find this usefull.
I had the same problem, with the same Tutorial. It turns out that I needed to just restart the Spork service, and all worked fine.
The solution posted by Tom L worked for me, but when I removed that line and restarted Spork, that also fixed the problem.
Hope that helps out any other people who are wary about deviating from the tutorial's code!
You should have used
rails generate rspec:install
instead of
rspec --init
and you wouldn't have had to modify the config file.
Don't do it now though or your application will break and you'll have to waste some more time figuring out why it broke.
Named routes should work if you put the following in rails_helper.rb not the spec_helper.rb:
checkout at my rails_helper.rb code
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
if Rails.env.production?
abort('The Rails environment is running in production mode!')
end
require 'rspec/rails'
require 'capybara/rails'
RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
config.include Warden::Test::Helpers
end
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
end

undefined method `mock_model'

I'm trying to use Rspec 1.3.1 for my rails application which is running on 2.3.8. I am able to 'stub' the models with stub_model method. But when I call mock_model, things go wrong and this is the stack trace I get
./spec/models/bucket_spec.rb:32: undefined method `mock_model' for Spec::Rails::Example::ModelExampleGroup::Subclass_2:Class (NoMethodError)
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:188:in `module_eval'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:188:in `subclass'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:55:in `describe'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/example/example_group_factory.rb:31:in `create_example_group'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/dsl/main.rb:28:in `describe'
from ./spec/models/bucket_test.rb:31
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:15:in `load'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:15:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:14:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/runner/options.rb:134:in `run_examples'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/lib/spec/runner/command_line.rb:9:in `run'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.1/bin/spec:5
from /usr/local/bin/spec:19:in `load'
from /usr/local/bin/spec:19
The bucket_spec.rb file:
require 'spec_helper'
describe Bucket, "creation" do
before(:each) do
#bucket = stub_model(Bucket, :id => 1, :name => "Below Proficient", :color => "green", :min_range => 0, :max_range => 30, :class_group_id => 1).as_new_record
end
it "should be valid with all the attributes set to some randowm values" do
#bucket.should be_valid
end
it "should be valid without min_range" do
#bucket.min_range = nil
#bucket.should be_valid
end
it "should be valid without max_range" do
#bucket.max_range = nil
#bucket.should be_valid
end
it "should be valid without class_group_id" do
#bucket.class_group_id = nil
#bucket.should be_valid
end
it "should not be valid without color" do
#bucket.color = nil
#bucket.should_not be_valid
end
it "should not be valid without name" do
#bucket.name = nil
#bucket.should_not be_valid
end
end
describe Bucket, "saving" do
#bucket = mock_model(Bucket)
#bucket.should be_valid
end
The spec_helper.rb file:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'spec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
#
#RSpec.configure do |config|
# # == Mock Framework
# #
# # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
# #
# # config.mock_with :mocha
# # config.mock_with :flexmock
# # config.mock_with :rr
# config.mock_with :rspec
#
# # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
#
# # If you're not using ActiveRecord, or you'd prefer not to run each of your
# # examples within a transaction, remove the following line or assign false
# # instead of true.
# config.use_transactional_fixtures = true
#end
Spec::Runner.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
end
The list of rspec gems
gem list rspec
*** LOCAL GEMS ***
rspec (1.3.1)
rspec-rails (1.3.3)
The list of rails gems
gem list rails
*** LOCAL GEMS ***
rails (2.3.8, 2.3.5)
Your call to mock_model is at the top level of your describe block which doesn't make sense
You can only do that inside a before(:each), an example (ie in the block passed to it) and places like that

Resources