Shoulda helpers don't work - ruby-on-rails

I have one spec:
require 'spec_helper'
# hmm... I need to include it here because if I include it inside describe block `method_missing` exception raises.
include Shoulda::ActionController::Matchers
describe CategoriesController do
include Devise::TestHelpers
render_views
context "new should render template :new" do
setup do
sign_in :user
get :new
end
should render_template(:new)
end
end
when I run rake spec I see this(but if i change context to it and move setup block contents to it block all works fine):
localhost:gallery rtest$ rake spec
(in /Users/rtest/Projects/gallery)
/Users/rtest/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S bundle exec /Users/rtest/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -Ilib -Ispec "./spec/controllers/categories_controller_spec.rb" "./spec/controllers/photos_controller_spec.rb" "./spec/helpers/categories_helper_spec.rb" "./spec/helpers/photos_helper_spec.rb" "./spec/models/category_spec.rb"
***
Pending:
CategoriesHelper add some examples to (or delete) /Users/rtest/Projects/gallery/spec/helpers/categories_helper_spec.rb
# Not Yet Implemented
# ./spec/helpers/categories_helper_spec.rb:14
PhotosHelper add some examples to (or delete) /Users/rtest/Projects/gallery/spec/helpers/photos_helper_spec.rb
# Not Yet Implemented
# ./spec/helpers/photos_helper_spec.rb:14
Category add some examples to (or delete) /Users/rtest/Projects/gallery/spec/models/category_spec.rb
# Not Yet Implemented
# ./spec/models/category_spec.rb:4
Finished in 0.0006 seconds
3 examples, 0 failures, 3 pending
/Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb:41:in `renders_template?': undefined method `assert_template' for #<Class:0x00000104839eb0> (NoMethodError)
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb:23:in `matches?'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/handler.rb:11:in `handle_matcher'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/extensions/kernel.rb:27:in `should'
from ./spec/controllers/categories_controller_spec.rb:17:in `block (2 levels) in <main>'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe'
from ./spec/controllers/categories_controller_spec.rb:11:in `block in <main>'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe'
from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/extensions/object.rb:7:in `describe'
from ./spec/controllers/categories_controller_spec.rb:6:in `<main>'
Loaded suite /Users/rtest/.rvm/gems/ruby-1.9.2-p0/bin/rake
Started
Finished in 0.003418 seconds.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 39993
My 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 'shoulda'
require 'shoulda/rails'
require 'shoulda/integrations/rspec2'
# 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
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, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
I am using rails 3. rspec/shoulda/factory_girl are included to the application by this code in Gemfile:
group :test, :development do
gem 'autotest'
gem 'factory_girl'
gem "shoulda"
gem "rspec-rails", ">= 2.0.0.beta.20"
end

I'm pretty sure that error is because you haven't wrapped your shoulda assertion inside an it block like so:
it { should render_template(:new) }
This is required when using Shoulda with RSpec.
should render_template(:new) on it's own will work with Test::Unit.

If I'm not mistaken, I've used Shoulda and I think the syntax is
should_render_template(:new)
and not
should render_template(:new)
which explains the 0 tests,0 assertions...

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.

Error while using RSpec + Capybara in Rails 4

I have a simple rails app which Im trying to introduce elementary tests in. Im following this url.
My application is structured as follows:
Im trying to test the single page: called Main Page.
In spec/features/main_pages_spec.rb I have the following code:
require 'spec_helper'
feature "soadevise" do
feature "Main Page" do
scenario "should have the content 'Main Page' "
visit '/main_page/home'
expect(page).to have_content('Main Page')
end
end
My spec/spec_helper.rb looks like this:
# 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
config.include Capybara::DSL
# 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"
end
When I run this command in the terminal:
MRMIOMP0903:soadevise $ bundle exec rspec spec/features/main_pages_spec.rb
I get the following error:
/Users/am/Desktop/x/xx/rails_projects/mysql_apps/soadevise/
spec/features/main_pages_spec.rb:6:
in `block (2 levels) in <top (required)>': undefined method `visit' for #
<Class:0x007fb7237377b0> (NoMethodError)
from /Users/am/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core 2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'
from /Users/am.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'
from /Users/am.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'
My gemfile contains these:
#For testing
group :development, :test do
gem "rspec-rails", "~> 2.14.1"
end
group :test do
gem "selenium-webdriver"
gem "capybara"
end
I refered to this link as well.
Can someone suggest what Im doing wrong?
You're calling feature twice. It should look like this:
require 'spec_helper'
feature "soadevise Main Page" do
scenario "should have the content 'Main Page'" do
visit '/main_page/home'
expect(page).to have_content('Main Page')
end
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

Rails rspec undefined local variable or method `render_views'

When running the rspec I get:
C:/www/kill/spec/games_controller_spec.rb:4:in block in <top
(required)>': undefined local variable or methodrender_views'
games_controller_spec.rb
require 'spec_helper'
describe GamesController, "creating a new game" do
render_views
fixtures :games
it "should redirect to index with a notice on successful save" do
Game.any_instance.stubs(:valid?).returns(true)
post 'create'
assigns[:game].should_not be_new_record
flash[:notice].should_not be_nil
response.should redirect_to(menu_items_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}
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
# 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
end
gems:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-2.7.0
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mocha-0.10.0
Your controller specs should be in the spec/controllers/ folder. However, you may want for some reason to have some other files that run controller specs (for example, I'm testing markup validation in a separate test file).
You can do this :
describe GamesController, "creating a new game", :type => :controller do
And this should do the trick !
You should place your controller specs inside a spec/controllers directory. RSpec is including these methods based on this, AFAIK.
In my case my test was already in spec/controllers/. I needed to add config.infer_spec_type_from_file_location! inside the RSpec.configure do |config| loop in spec_helper.rb. I had updated rspec from 2.x to 3.x without realizing it, and that config is needed for controller tests from 3.x.
If you test the views, RSpec have the spec/requests directory for that, it will render views by default. (See the doc)
this problem may be caused by your Gem rspec-rails version. downgrade it back to 2.x solved my problem:
# edit your Gemfile
gem "rspec-rails", "2.14.2"

When trying to run rspec, I get "uninitialized constant ActiveModel"

When I run rspec spec I get the following:
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-rails-2.7.0/lib/rspec/rails/extensions/active_record/base.rb:26:in `': uninitialized constant ActiveModel (NameError)
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-rails-2.7.0/lib/rspec/rails/extensions.rb:1:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-rails-2.7.0/lib/rspec/rails/extensions.rb:1:in `'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-rails-2.7.0/lib/rspec/rails.rb:8:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-rails-2.7.0/lib/rspec/rails.rb:8:in `'
from /Users/noahc/Dropbox/perfect_setup/spec/spec_helper.rb:4:in `require'
from /Users/noahc/Dropbox/perfect_setup/spec/spec_helper.rb:4:in `'
from /Users/noahc/Dropbox/perfect_setup/spec/controllers/pages_controller_spec.rb:1:in `require'
from /Users/noahc/Dropbox/perfect_setup/spec/controllers/pages_controller_spec.rb:1:in `'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `block in load_spec_files'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `map'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:in `run'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_in_process'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'
My spec_helper.rb looks like this:
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require 'rspec/rails'
require 'rspec/autorun'
require 'spork'
Spork.prefork do
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
ActiveSupport::Dependencies.clear
end
end
Spork.each_run do
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each {|f| load f}
end
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
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
end
Dir[Rails.root.join('spec/support/**/*.rb')].each{|f| require f}
If I delete my pages_controller_spec file the errors go away. But I have zero specs to run.
The error returns when I have something even as simple as this:
require 'spec_helper'
describe PagesController do
it "should do something..."
end
Also, if I add any tests no matter where I get the same error.
Any clues on other things I can try?
Why are you running rspec spec? The typical thing to run is rake spec.
Try bundle exec rspec spec or bundle exec rake spec.
If that doesn't work, try to see if something is wrong with the rest of your environment -- try bundle exec rails console and bundle exec rails server
Another thing to check, is there anything odd in .rspec in your project file, or ~/.rspec?
Found this thread while debugging the same symptoms. Here is another reason for the error: I had run
rspec --init
but had failed to run
rails generate rspec:install
Doing the latter fixed the problem.
In my case
gem "spork-rails", "~> 4.0.0"
was missing in ./Gemfile.

Resources