Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9235021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:55:41+00:00 2026-06-18T06:55:41+00:00

This question is NOT about how to test controllers in a rails app. Developing

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:55:42+00:00Added an answer on June 18, 2026 at 6:55 am

    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 with rspec --init). Then spec/rails_controller_integration_spec.rb will look like this.

    rspec/rails does the necessary requires, among them rspec/rails/example which sets up example group types based on metatags. The metatag :type => :controller drives the inclusion of the proper group module RSpec::Rails::ControllerExampleGroup which provides you with all the goodies of rails controller specing as well as all the goodies of ActionController::TestCase like get/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 TestTailsApp1 and TestTailsApp2. any advice?

    require 'spec_helper'
    require 'my_gem'
    
    require 'rails'
    require 'action_controller/railtie' # allows ActionController::Base
    # crucial part here:
    require 'rspec/rails'
    # note that require 'rspec-rails' does not work
    
    module TestRailsApp
      class Application < Rails::Application
        # app config here
        # config.secret_token = '572c86f5ede338bd8aba8dae0fd3a326aabababc98d1e6ce34b9f5'
        # routes.draw do
        #   resources :models
        # end
      end
    
      class ApplicationController < ActionController::Base
        # setup
      end
    
    end
    
    describe 'My gem' do
    
      context "in a Rails controller", :type => :controller do
    
        controller(TestRailsApp::ApplicationController) do
          extend(RSpec::Rails::ControllerExampleGroup::BypassRescue)
          # example-specific setup for anonymous controller
          # https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/anonymous-controller
          def index
          end
        end
    
        before(:each) do
          # request needs to be setup to avoid path setting error
          @request = ActionController::TestRequest.new
        end
    
        describe "#index" do
          it "works" do
            get :index
            response.body.should == 'index content'
          end
        end
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is not about caching. I need this in-memory table for many small
This question is not about which is the best, it is about which makes
This question is not about 'best' barcode library recommendation, we use various products on
(note that this question is not about CAS, it's about the May fail spuriously
For starters, this question is not so much about programming in the NetBeans IDE
This question is not technical, but is still about programming. What is the funniest,
My question is not about how to solve this error(I already solved it) but
This question calls for "line numbers". If you do not care about line numbers
I've this question about pass some instances by ref or not: here is my
Not much to say about this question...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.