Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
David Rodríguez
@deivid-rodriguez
Hi! I'd like to know whether there's a recommended configuration to test ApplicationController, just like the anonymous controller in RSpec: https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/anonymous-controller
Thanks!!
Mike Moore
@blowmage
there is not. ActionController::TestCase needs the router to be aware of the controller, making it very difficult to build and test anonymous controllers
David Rodríguez
@deivid-rodriguez
Thanks @blowmage , appreciated
Mike Moore
@blowmage
the fact that your controller inherits from AppicationController is an implementation detail. It could get the same set of behavior by including a module, or inheriting from another controller. IMO you should test the behavior on the controller you test, not the pieces you build it from.
David Rodríguez
@deivid-rodriguez
What about functionality inherited by all controllers, in a before_action, for example? Right now I'm just picking one controller and action to test it, but it feels... weird.
Mike Moore
@blowmage
Like testing all objects, you need to test what your objects do, not how they are implemented to do it. The fact that you are inheriting that functionality is an implementation detail. Test the boundaries of your objects, their public API, not the guts.
Jimmy Zhang
@mengqing
hi all, how would i do stub chain using minitest?
Mike Moore
@blowmage
What, specifically, are you trying to do?
Jimmy Zhang
@mengqing
eg, in rspec, I can do a.stub_chain(:b, :c, :d, :e).and_return(1)
anyway to achieve this in minitest?
Mike Moore
@blowmage
Nothing in minitest. There may be a plugin. Minitest does not promote mocking and stubbing, so you will likely need to use an alternate mock/stub library.
Or change your approach, which is what minitest encourages. :)
David Rodríguez
@deivid-rodriguez
@blowmage I'm trying to test functionality, not an implementation detail. Namely, check that the locale is correctly set according to certain priorities: url param, user browser or a default. To test it in minitest I have to pick one controller and one action and run the test against those. In rspec I can create a fake controller just inheriting that behaviour and test it in isolation. Maybe your whole point is that the "minitest way" is better, just making sure we are on the same page.
David Rodríguez
@deivid-rodriguez
@blowmage Thanks! Unfortunately I checked those links before asking here but couldn't make it work.
Gonzalo Aune
@gonzaloaune
hey guys, one question, I'm testing controllers in my rails app and Im using an authentication system where I join some header values + HTTP method + PATH of the url I'm hitting, the thing is in minitest to test the controller I need to do posto :create for example, but I need something like post 'api/v1/controller', any way to achieve something like this? Thanks.
Mike Moore
@blowmage
You can't access multiple controllers in controller tests. If api/v1/controller is a different controller then you should use an integration test.
Gonzalo Aune
@gonzaloaune
No, is the same controller, but the thing is, when I do request.fullpath it doesn't return the proper url
Mike Moore
@blowmage
Sounds like your router resolves the controller for multiple paths then.
Edgar Ortega
@EdgarOrtegaRamirez
Hey guys, first time here, I'm using minitest-rails v3.0.0.rc1 and getting NoMethodError: undefined method 'headers' for nil:NilClass on @request.headers["Content-Type"] = "application/json" in a before block, it worked in version 2.1, I will appreciate if you guys have an idea, thanks.
Mike Moore
@blowmage
Hey Edgar, controller tests are deprecated in rails 5, so you should convert to integration tests. Those instance variables don't exist in the acceptance tests.
You can also weigh in on how to support controller tests on blowmage/minitest-rails#194
Edgar Ortega
@EdgarOrtegaRamirez
@blowmage thanks, I used this patch and it's working right now.
Mike Simkins
@msimkins
Can you stop generating controller tests in Rails 4
Mike Moore
@blowmage
Rails doesn't have an option to do that AFAIK
Mike Simkins
@msimkins
I am trying to switch to mini from RSpec, and there you can pass an option controller_specs: false, and it does not generate them, I was hoping I missed the option in Minitest
Mike Moore
@blowmage
No, we stick to the rails defaults as much as possible.
Mike Simkins
@msimkins
Thanks @blowmage, I thought that was the case, I thought with the comments about controller tests being deprecated in Rails5, that it may have been something I could do, Ill just delete the folder, as for some strange reason I can't make the authentication work right, but it works fine as an integration test <sigh>
Mike Moore
@blowmage
ActionController::TestCase is being deprecated, but controller tests remain. they will just use ActionDispatch::IntegrationTest now
Anton Trapp
@AntonTrapp
Thanks @blowmage - just joined this room and already the first useful information in the first entry :)
Mike Moore
@blowmage
👍
Sebastián
@sebastian-palma
Hi guys, I'm having a doubt using Minitest and Rails 5, when I try to test for a 404 response and I get a 200.
The differences is when I try with get /users/z which responds with 404, but when I do it with get users_path, params: { id: 'z' } I have a 200 response.
Mike Moore
@blowmage
¯(ツ)
Chris M
@CheezItMan
Just curious is there a way for Minitest-Rails to default to spec style tests on new rails apps
Mike Moore
@blowmage
there is a bug in minitest-rails-capybara. it should generate spec style tests by default, but its flipped. you can try configuring it in application.config.yaml
config.generators do |g|
g.test_framework :minitest, spec: true
end
Mike Moore
@blowmage
pushed 3.0.1 to fix the bug
Chris M
@CheezItMan
Thanks Mike, I'm not using capybara yet, but it still seems to generate:
class PostTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end
end
Oleksandr T.
@a-tarasyuk

Minitest::Spec has let(:test) { } - is it the same as

def test
end

in Minitest::Unit?

Mike Moore
@blowmage
yes
Oleksandr T.
@a-tarasyuk
@blowmage thanks )
Nicholas
@nicholasshirley

Hi, I'm trying to test the deletion of an image associated with a user profile with Paperclip that is liked to an S3 bucket. I don't actually want the test to hit S3 though, is there a way to do this in Minitest?

Here is a SO post with the code that I've tried http://stackoverflow.com/questions/43760246/minitest-test-for-removing-paperclip-image-linked-to-s3-without-actually-upload

Mike Moore
@blowmage
Delegate the responsibility to hit S3 to something that your app owns, and then mock the call to it. If paperclip makes that too difficult, you can mock a call inside of paperclip, or try mocking the HTTP request.
Punita Ojha
@punitaojha
This message was deleted
Tessy Joseph John
@tessie
Hi I am getting : undefined method `get' in my test controller class
can some one help me
Mike Moore
@blowmage
That usually means it isn't recognized as a controller test