0

I created a small rails app using StimulusReflex and testing it with Rails' standard minitest framework.

I want to write a "controller" test that invokes a reflex and tests the controller response, but that seems to be impossible. Any hint on how to do this?

Alexander Presber
  • 6,429
  • 2
  • 37
  • 66

1 Answers1

0

There is a Gem you can add to help you with reflex testing stimulus_reflex_testing: https://github.com/podia/stimulus_reflex_testing

Then you will be able to have test such as this:

# app/reflexes/post_reflex.rb
class PostReflex < ApplicationReflex
  def find_post
    @post = Post.find(params[:id])
  end
end

reflex = build_reflex(method_name: :find_post, url: edit_post_url(post), params: { id: post.id })
reflex.run
reflex.get(:post) #=> returns the @post instance variable

The gem also includes some spec matchers. But people in the SR community mostly use system tests.

Roland Studer
  • 4,315
  • 3
  • 27
  • 43
  • Thanks for your answer! I think this is not really what I was looking for, I was interested in the combination reflex + controller action and this only tests the reflex, right? – Alexander Presber Nov 25 '21 at 12:02