Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSpec/Rails Issues with 1.2.1 #821

Closed
danielmorrison opened this issue Jan 15, 2024 · 1 comment · Fixed by #827
Closed

RSpec/Rails Issues with 1.2.1 #821

danielmorrison opened this issue Jan 15, 2024 · 1 comment · Fixed by #827

Comments

@danielmorrison
Copy link
Contributor

Still having issues under 1.2.1 with RSpec/Rails. Not sure I have time tonight to get a PR, so I'm posting some quick notes.

What I think is happening is: rspec-rails uses ActiveSupport::TestCase, so both of these blocks are running and clobbering each other:

if defined?(RSpec) && RSpec.respond_to?(:configure)
RSpec.configure do |config|
config.include Flipper::TestHelp
config.before(:each) do
flipper_reset
flipper_configure
end
end
end
if defined?(ActiveSupport)
ActiveSupport.on_load(:active_support_test_case) do
ActiveSupport::TestCase.class_eval do
include Flipper::TestHelp
setup :flipper_configure
setup :flipper_reset
end
end

In fact, if I comment out the RSpec chunk, my tests go back to passing.

@danielmorrison
Copy link
Contributor Author

@bkeepers got working on a failing spec for you:

ENV["RAILS_ENV"] = "test"
require 'rubygems'
require 'bundler/setup'
require 'rails'
require 'rails/test_help'

# Not worth trying to test on old Rails versions
return unless Rails::VERSION::MAJOR >= 7

require "capybara/cuprite"
require "flipper"
require "flipper/test_help"

require 'action_dispatch/system_testing/server'
ActionDispatch::SystemTesting::Server.silence_puma = true

class TestApp < Rails::Application
  config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
  config.eager_load = false
  config.logger = ActiveSupport::Logger.new(StringIO.new)
  routes.append do
    root to: "features#index"
  end
end

TestApp.initialize!
require "rspec/rails"

class FeaturesController < ActionController::Base
  def index
    render json: Flipper.enabled?(:test) ? "Enabled" : "Disabled"
  end
end

RSpec.describe "TestHelpTest", type: :system do

  before do 
    # Any driver that runs the app in a separate thread will test what we want here.
    driven_by :cuprite

    # Ensure this test uses this app instance
    Rails.application = TestApp.instance
  end
  
  it "configures a shared adapter between tests and app" do
    Flipper.disable(:test)
    visit "/"
    expect(page).to have_text("Disabled")

    Flipper.enable(:test)
    visit "/"
    expect(page).to have_text("Enabled")
  end
end

Looks like you're already thinking about this in #822 a bit.prepend doesn't fix it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant