wrong icon indicating copy to clipboard operation
wrong copied to clipboard

wrong takes over `expect`... unexpectedly

Open jjb opened this issue 12 years ago • 1 comments

I have this spec:

it "should create Foo" do
  expect{
    post :create, foo: {owner_id: 1, bar_id: 1}
  }.to change(Foo, :count)
  expect(assigns(:foo).owner_id).to eq(1)
  expect(assigns(:foo).bar_id).to eq(1)
  expect(response).to redirect_to(root_path)
end

Run with everything but the last line, it succeeds. But with the last line, this happens:

1) FoosController should create group ownership
   Failure/Error: expect(response).to redirect_to(root_path)
   RuntimeError:
     You must pass a block to Wrong's assert and deny methods
   # /Users/john/src/wrong/lib/wrong/assert.rb:31:in `rescue in assert'
   # /Users/john/src/wrong/lib/wrong/assert.rb:27:in `assert'
   # ./spec/controllers/foos_controller_spec.rb:9:in `block (2 levels) in <top (required)>'

It's as if alias_assert :expect is being invoked, but just for that one spec.

I've experimented with different combinations and orderings and determined that the problem only happens when redirect_to is present.

Any ideas?

jjb avatar Oct 12 '13 17:10 jjb

I saw the same here. My assumption was that expect ... redirect_to is actually using assert deep down under the hood, since I get the same exact error when I try to call any of the "old guard" assert matchers like assert_redirected_to after including Wrong.

I interpret this to mean that once you install Wrong, you must use its DSL exclusively; it may break any of the old assertion styles. If that's necessary for it to do the magic it does, then that's fine, but I wonder if that warning could be made clearer in the readme? Or even better, perhaps there's an option I don't know about to name the assert method something different, so it doesn't clobber everything that depends on the old assert?

EDIT: It just occurred to me that adding the TestUnit and/or MiniTest adapters might help here, though I don't have the time to test this at the moment.

require 'wrong/adapters/test_unit'

topherhunt avatar Jan 14 '15 02:01 topherhunt