This question is NOT about how to test controllers in a rails app.
Developing a gem I want to test if my gem integrates in a rails controller.
So running rspec in the gem root is outside the rails environment.
Now how do I write say a controller test which can use the rspec controller example group helpers like get or post?
IN particular if I set a metatag :type => :controller on an example group , how does rspec set up the rails environment and how can i hook into that in order to say set up routes, etc.
I’d rather not have to set up an entire rails app skeleton mostly empty. But I cannot even find info on how to do that. What is best practice to test a gem integrating to rails app or multiple frameworks.
These sources came closest to what I am after:
Test (with RSpec) a controller outside of a Rails environment
but this is for test unit.
http://railsware.com/blog/2012/01/07/testing-gem-integration-with-multiple-ruby-frameworks/
but this is for capybara which directly hooks in a rails app class.
thanks all
Below is a nice minimal example of a rails controller integration test from a gem.
my_gem. Assume that you are in a gem root with simple rspec setup (say withrspec --init). Thenspec/rails_controller_integration_spec.rbwill look like this.rspec/railsdoes the necessary requires, among themrspec/rails/examplewhich sets up example group types based on metatags. The metatag:type => :controllerdrives the inclusion of the proper group moduleRSpec::Rails::ControllerExampleGroupwhich provides you with all the goodies of rails controller specing as well as all the goodies ofActionController::TestCaselikeget/post.Hope this helps.
What I still don’t get is how the Rails environment gets assigned. In particular what if I would like to set up two apps
TestTailsApp1andTestTailsApp2. any advice?