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

wrong takes over expect... unexpectedly #37

Open
jjb opened this issue Oct 12, 2013 · 1 comment
Open

wrong takes over expect... unexpectedly #37

jjb opened this issue Oct 12, 2013 · 1 comment

Comments

@jjb
Copy link

jjb commented Oct 12, 2013

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
Copy link

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'

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

No branches or pull requests

2 participants