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
#let doesn't appear to be invoked when defined in a top level describe block in 2.13.0 #817
Comments
The behavior hasn't purposefully changed. You may have found a regression. I tried to repro your case in an isolated example (since I can't run the spec you have above without having your app): require 'ostruct'
describe "MyController" do
before :all do
@client = OpenStruct.new(authentication_token: 'abcd')
end
let(:default_parameters){{auth_token: @client.authentication_token}}
context '#index' do
it 'should be authorized' do
expect(default_parameters).to include(auth_token: 'abcd')
end
end
end ...and it passes just fine for me. I'm not sure what "let doesn't appear to be invoked" means -- you are calling the method it defines in your example. What error are you getting? Please include the full backtrace (with |
Hi, let me try to explain myself more clearly. I have a helper in module RequestHelpers
extend ActiveSupport::Concern
included do
[:get, :post, :put, :delete, :head].each do |method|
class_eval <<-EOV
def #{method} path, parameters = nil, headers = nil
parameters = combine_parameters parameters, default_parameters
super #path, parameters, headers
end
EOV
end
end
def default_parameters
end
private
def combine_parameters argument, default
if argument.is_a?(Hash) && default.is_a?(Hash)
default.merge argument
else
argument || default
end
end
end This helper is included in my So my example spec looks like this: describe PostsController do
before :all do
@client = Client.create auth_token: 'foobar'
end
let(:default_parameters){{auth_token: @client.authentication_token}}
context '#index' do
it 'should be authorized' do
get :index, {filter: 'active'}
end
end
end In this case, the |
Thanks, that's helpful...although, you still haven't explained how it is specifically broken on 2.13.0. Are you getting an error when the |
When calling When you would call I'll try to abstract this example from my app into a sample app. |
Thanks, that would be helpful. |
Today I have run into the very same issue, present both in It goes like this: describe ...
let(:params) do
{
something: something
}
end
context ...
it "..."
something = Something.new(params)
...
other = Something.new(params) On the 2nd invocation of |
I'd be happy to take a look and solve this issue if someone can provide a reproducible example I can run. I haven't been able to repro it in my attempts. |
I'm still planning to give you an example. But I won't be able to do that before next week. On 12 Mar 2013, at 21:12, Myron Marston notifications@github.com wrote:
|
Without the context of the rest of this thread, the first question that comes to my mind from @pjg's example is whether |
@dchelimsky That was a very good question. |
I'm experiencing something possibly similar with the following helper: let(:body) { JSON.parse(response.body) } Inside an
|
@moll -- without seeing your full example, it's impossible to know for sure what's going on, but one thing to bear in mind is that |
@myronmarston didn't we merge in that change to the require order of
I'd guess the order in which the let / var in the helper is defined has changed... |
I don't understand what you are referring to... |
I was thinking of #845 |
We haven't cut a release that includes #845 yet. |
Then consider my comment redundant :) |
Hi @myronmarston, I finally found the time to abstract this issue into an example app. You can find it at https://github.com/jeroenj/rspec-demo. After some more investigation it looks like the helper method I hope this could help you (or us) to get a better picture of what is going on. |
Thanks for putting that together, @jeroenj. It'll definitely help us track this down. |
@myronmarston: I did check |
@moll I'm pretty sure |
@JonRowe Rewound? You mean reading from |
The raw Rack
|
@jeroenj The short version of this problem is that it's a combination of shadowing the let variable, and something in The longer version... (for the benefit of @myronmarston @samphippen @soulcutter) The problem with the original issue here is the shadowing of the let variable. Prior to '2.13.0' we were just applying On pure However when combined with |
The following code is a simplified snippet of one of my controller specs. After updating RSpec to 2.13.0 (from 2.12.2) the
let
block doesn't get invoked.However when I put it inside the
context '#index'
block, it does get invoked and the default_parameters are set as expected.Has this behavior changed in 2.13.0 and am I doing it wrong, or is it really broken now?
The text was updated successfully, but these errors were encountered: