thoughtbot/shoulda-context

Shoulda context is incompatible with minitest-focus

Closed this issue · 3 comments

When I apply focus to a method that is encapsulated inside shoulda-context. It always only executes the first method within the context, despite me focusing on the second method.

require 'test_helper'

class StaffsControllerTest < ActionController::TestCase
  context "ab" do

    should "a" do
      flunk "a"
    end

    focus
    should "b" do
      flunk "b"
    end 
  end
end

I hope this can replicate the issue.

I ran into the same issue and when I dove in, I realize it's because shoulda-context is defining these test methods in a weird order and dynamically. I have this patch that achieved what I needed to run a single test. Hope it can be useful to you!

https://gist.github.com/ivantsepp/bbf6cc4f1373295a79583fd45878f7d2

Hey there, just revisiting old issues and seeing whether they are still relevant. As @ivantsepp mentioned, the way that Shoulda Context works is that when you use context, it will store all of the tests that need to be defined and then define them once it evaluates the block. Therefore, if you use focus it doesn't know which method to apply that to. If it defined methods immediately instead, then this might work, but unfortunately that would require going into the gem and rearchitecting how it works. I'm not sure how long that will take, but I'll keep this open in the meantime.

I'm going to close this issue. If someone wants to take a crack at this and submit a PR then that's cool, but as mentioned this is not a trivial task and it doesn't seem to be a popular want.