sconover / wrong

Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail.
MIT License
434 stars 31 forks source link

wrong takes over `expect`... unexpectedly #37

Open jjb opened 10 years ago

jjb commented 10 years ago

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?

topherhunt commented 9 years ago

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'