Closed bobf closed 8 years ago
Greatly appreciate all the detail!
I think this is actually a flaw in the plugin generator - I'd expect a gem that relies on Rails::Engine
to have require 'rails/engine'
, instead of just hoping something else along the way will load it. Open to other thoughts on the matter though :)
By the way, the initial reason for creating this issue was that I couldn't get rspec to run (error about needing a rack-test application present) but, in putting together this recipe, I noticed that if I copy more of the sample spec_helper.rb
than I thought I needed, my specs now run (I have a passing test visiting a page inside my internal app). So that's the most important bit for me - rackup
would just be a bonus.
Perhaps the docs could be a bit more specific about exactly what and why needs to go into spec_helper.rb
?
I've not used the rspec-rails generator from within an engine - I'm not sure it was built for that purpose? The spec_helper.rb
in the README is what I expect should work - if you're able to reproduce your original rack-test error, that'd be super helpful.
Interesting ! Adding require 'rails/engine'
to my engine.rb
gives a new error:
$ rackup
/Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:531:in `routes': uninitialized constant Rails::Engine::ActionDispatch (NameError)
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/railtie.rb:194:in `public_send'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/railtie.rb:194:in `method_missing'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:380:in `isolate_namespace'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/lib/hierarchy_navigator/engine.rb:5:in `<class:Engine>'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/lib/hierarchy_navigator/engine.rb:4:in `<module:HierarchyNavigator>'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/lib/hierarchy_navigator/engine.rb:3:in `<top (required)>'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/lib/hierarchy_navigator.rb:1:in `require'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/lib/hierarchy_navigator.rb:1:in `<top (required)>'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler/runtime.rb:76:in `require'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler/runtime.rb:72:in `each'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler/runtime.rb:72:in `block in require'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler/runtime.rb:61:in `each'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler/runtime.rb:61:in `require'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/bundler-1.10.0.rc/lib/bundler.rb:133:in `require'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/config.ru:4:in `block in <main>'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/config.ru:in `new'
from /Users/bobfarrell/dev/ph/hierarchy_navigator/config.ru:in `<main>'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:272:in `start'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:147:in `start'
from /Users/bobfarrell/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.6.4/bin/rackup:4:in `<top (required)>'
from /Users/bobfarrell/.rbenv/versions/2.1.6/bin/rackup:23:in `load'
from /Users/bobfarrell/.rbenv/versions/2.1.6/bin/rackup:23:in `<main>'
Sorry if there is an obvious solution to this, I'm reasonably new to Rails internals, especially with engines.
Sure thing. With this spec/spec_helper.rb
:
require 'combustion'
Combustion.initialize! :all
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.order = :random
Kernel.srand config.seed
end
I get this error when running rspec
ArgumentError:
rack-test requires a rack application, but none was given
It seems obvious now that adding these two lines after Combustion.initalize! :all
would solve the problem, but it was difficult from the example you provided to figure out what was expected to be in a "standard" spec_helper.rb
and what was expected to be added by the user:
require 'rspec/rails'
require 'capybara/rails'
Maybe a barebones spec_helper.rb
would be better, i.e. the minimum that it must contain in order for Combustion to work ?
The point being above that it seemed odd to me to need to require rspec/rails
for this to work, given that the rspec:install
generator does not include them, yet rspec
itself works fine. Does that make sense ?
Hey, bundle exec rackup
works for me now ! No idea what the hell I did to make it work. :)
Anyway, thanks for the help earlier and for the great gem. Took a while to get off the ground but will definitely be using this for future engine testing now I know how to get it going.
Cheers,
Great to know you got it working - I'll look into improving the documentation for the spec_helper.rb
example :)
Anybody have an app I can look at? I'm getting the same error @bobf was getting about ActionDispatch. I'm just trying to run tests.
@NullVoxPopuli I don't suppose the source of the engine/railtie you're working on is visible on GitHub?
I can point to a couple of gems of my own that use Combustion, if that's helpful, though I generally don't make use of the controllers/views/routing in my engines:
I really hope this isn't a duplicate of #27 - apologies if so !
Gemfile:
spec/spec_helper.rb
(I guess this isn't relevant ?)Let me know if you need any more info. Thanks !