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
Testing on Rails with RSpec? #35
Comments
|
I don't really use RSpec, but I'll tweet about it to see if someone has an idea! |
|
Thanks! |
|
Hmm, may have found an unsatisfying answer to my own question: http://stackoverflow.com/questions/15026571/why-does-rspec-rails-skip-the-middleware |
|
As the SO post says, controller tests skip the Rack stack and you'll need to use RSpec Request Specs if you need to fire the middleware stack. |
|
Hmm, yeah. I guess we can close this then. @steveklabnik I don't know how much sense it makes, but any thought to moving this into the controller layer rather than having it be a middleware? By moving it to an |
|
That would tie this to Rails as opposed to Rack. |
|
@steveklabnik Are Railties typically used outside of rails? I was thinking it would be possible to have the railtie set up an If it's something you think is appropriate to be part of this I can clean it up and pull request it. |
|
We only inject railties into Rails projects, so it'd have to be the same thing here. I'm not sure I'm interested in making the code arguably worse (around filters are not the way this is supposed to be done) to satisfy an rspec edge case. |
Agreed. I wonder if an addition to the I assume something similar needs to be said about Rails + MiniTests controller vs. functional tests? (I've not used the standard test stack in Rails in a long time, so someone else should confirm/deny.) |
|
Yeah, I wouldn't mind a README note. |
|
@steveklabnik @stevenharman I'm not too familiar with middleware. Why is something like this not "supposed" to be solved with an around filter? I guess my rationale was that if the mess is being made in the application layer, it would be good to have it being cleaned up there, too. Though admittedly my motivation was testability. |
|
RequestStore is intended to be a lower-level component of your application stack, operating at the Rack level makes it available to all portions of your stack which are built upon Rack. For example, mounted Sinatra apps, or other mounted Rails Engines. On the other hand, Rails' controller |
|
So would you use it for passing data between your different services? |
|
It's more that if it's a middleware, your entire application can rely on this behavior. If it's in the controller, only your controller can. |
|
You can also clear it by your self before(:each) do
RequestStore.clear!
endto your spec_helper.rb RSpec.configure do |config|
*
end |
|
Yeah, we have that in our spec helper. The issue is that we can't really test that it's working for us unless we find some way of doing it through an integration spec. |
I'm having some trouble getting my controller tests passing, but RequestStore is not clearing out at the end of the request. I have the following code in my
ApplicationController:And here are my specs:
The last two specs fail:
I saw this bit in the readme about inserting it for
Rack::Testand played around with that with no luck. Any idea how I can get this working?The text was updated successfully, but these errors were encountered: