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

set_flash[:foo].now matcher does not care if flash[:foo] really set .now #750

Closed
aried3r opened this issue Jul 3, 2015 · 4 comments
Closed

Comments

@aried3r
Copy link

aried3r commented Jul 3, 2015

I want to assert that a flash.now[:foo] uses .now, but the test passes, even if .now is not set.

Code:

# controller.rb, simplified, authorisation, authentication etc left out
def create
  @project = Project.new(project_params)
  if @project.save
    flash[:success] = 'Project successfully created'
    redirect_to projects_path
  else
    flash[:alert] = 'Project could not be created.'
    render 'new'
  end
end

# spec
it 'sets a flash.now' do
  post :create, invalid_params
  is_expected.to set_flash[:alert].to('Project could not be created.').now
  # passes!
end

The reverse is not true, btw. If flash.now[:foo] is set in the controller but not in the spec, the test fails.

Rails 4.2.3
Ruby 2.2.2
shoulda_matchers 2.8.0

@maurogeorge
Copy link
Contributor

Hi @aried3r thanks for report.

I worked at the master, that will be the 3.0.0, I am not sure if we will support 2.x after the 3.0.0 is released. But on master the problem was that when you call the now qualifier after defining call the [] and to is instantiated a new matcher that does not know about the previous values, take a look at the PR for a detailed explanation.

So maybe the following code works on 2.8.0, I know that this works on 3.0.0 even before the PR.

is_expected.to set_flash.now[:alert].to('Project could not be created.')

@mcmire what you think about add this on the 3.0.0 milestone?

@aried3r
Copy link
Author

aried3r commented Jul 6, 2015

So maybe the following code works on 2.8.0

It doesn't for me, sadly. I currently don't have the time to test this with the 3.0.0-rc version (with all the changes going on there), but I'd be glad to help you guys out next week. This gem helped me so much, I'd be glad to be of help.

@mcmire
Copy link
Collaborator

mcmire commented Jul 7, 2015

This might be an issue with 3.0, too, actually. I'm not going to let it hold up the release, though, as it's been in development forever and I'd rather get it out sooner rather than later. So I'll include a fix in the next release, but a PR is certainly still welcome.

@mcmire
Copy link
Collaborator

mcmire commented Sep 22, 2015

Closing this in favor of #755.

@mcmire mcmire closed this as completed Sep 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants