After removing ActiveRecord my specs fails to load.
djpate opened this issue · 5 comments
I have been using this gem for the last couple of weeks without issues.
But when I tried to remove ActiveRecord from my dependencies it fails to start my specs now.
rspec
NoMethodError: undefined method `setup' for #<Class:0x5b9a4e8e>
method_missing at org/jruby/RubyBasicObject.java:1592
block in TemplateAssertions at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rails-controller-testing-0.0.3/lib/rails/controller/testing/template_assertions.rb:10
module_eval at org/jruby/RubyModule.java:2693
append_features at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/activesupport-5.0.0.beta2/lib/active_support/concern.rb:120
include at org/jruby/RubyModule.java:2473
safe_include at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1065
block in configure_group at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1059
each at org/jruby/RubyArray.java:1560
configure_group at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1057
configure_group at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/world.rb:87
set_it_up at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:356
subclass at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:323
block in describe at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:219
block in describe at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/dsl.rb:41
block in describe at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/dsl.rb:79
<top> at /home/pate/lookout/git/alexandria/spec/lib/datastore/adapters/couchbase_spec.rb:2
load at org/jruby/RubyKernel.java:955
block in (root) at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:1
load at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:296
load_dependency at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:268
block in load at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:296
each at org/jruby/RubyArray.java:1560
load_spec_files at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105
load_spec_files at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105
setup at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96
run at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84
run at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69
<top> at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37
load at org/jruby/RubyKernel.java:955
<eval> at /home/pate/.rvm/gems/jruby-9.0.5.0/gems/rspec-core-3.1.7/exe/rspec:4
eval at org/jruby/RubyKernel.java:976
<top> at /home/pate/.rvm/gems/jruby-9.0.5.0/bin/rspec:1
Any ideas?
gem install rails -v 5.0.0.beta2
rails new repro --api #install rspec-rails and rails-controller-testing
rails generate rspec:install
in spec/rails_helper.rb
add
config.include Rails::Controller::Testing::TestProcess
config.include Rails::Controller::Testing::TemplateAssertions
config.include Rails::Controller::Testing::Integration
remove line 25, 29, 34.
it should look like this
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# 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 migrations 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 = true
# 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!
config.include Rails::Controller::Testing::TestProcess
config.include Rails::Controller::Testing::TemplateAssertions
config.include Rails::Controller::Testing::Integration
end
in config/application.rb, remove line 7
require "active_record/railtie"
delete config/initializers/active_record_belongs_to_required_by_default.rb
create a bogus spec like test_spec.rb
require 'rails_helper'
describe ApplicationController do
end
run rspec
rspec
/home/pate/.rvm/gems/ruby-2.2.3/gems/rails-controller-testing-0.1.0/lib/rails/controller/testing/template_assertions.rb:10:in `block in <module:TemplateAssertions>': undefined method `setup' for #<Class:0x00000005a26200> (NoMethodError)
from /home/pate/.rvm/gems/ruby-2.2.3/gems/activesupport-5.0.0.beta2/lib/active_support/concern.rb:120:in `class_eval'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/activesupport-5.0.0.beta2/lib/active_support/concern.rb:120:in `append_features'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1065:in `include'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1065:in `safe_include'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1059:in `block in configure_group'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1057:in `each'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1057:in `configure_group'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/world.rb:87:in `configure_group'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:356:in `set_it_up'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:323:in `subclass'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:219:in `block in define_example_group_method'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/dsl.rb:41:in `block in expose_example_group_alias'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/dsl.rb:79:in `block (2 levels) in expose_example_group_alias_globally'
from /home/pate/tmp/repro/spec/test_spec.rb:2:in `<top (required)>'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /home/pate/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /home/pate/.rvm/gems/ruby-2.2.3/bin/rspec:23:in `load'
from /home/pate/.rvm/gems/ruby-2.2.3/bin/rspec:23:in `<main>'
from /home/pate/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
from /home/pate/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'
Ok I just had a look at this. This is because RSpec doesn't load their SetupAndTeardownAdapter
if ActiveRecord is not being used See https://github.com/rspec/rspec-rails/blob/a6bdb463d7676d4160d3881a4605d3362d210a74/lib/rspec/rails/fixture_support.rb#L5-L7.
To work around the issue, add
RSpec.configure do |config|
config.include ActiveSupport::Testing::SetupAndTeardown
config.include Rails::Controller::Testing::TestProcess
config.include Rails::Controller::Testing::TemplateAssertions
config.include Rails::Controller::Testing::Integration
end
cc @rafaelfranca Last issue closed :) Can we make a new release?
Thank you!