{"id":26886220,"url":"https://github.com/henrahmagix/stimulus_tests","last_synced_at":"2026-04-15T15:43:33.147Z","repository":{"id":285283005,"uuid":"957602334","full_name":"henrahmagix/stimulus_tests","owner":"henrahmagix","description":"Test your Stimulus controllers in Rails!","archived":false,"fork":false,"pushed_at":"2025-03-30T20:01:57.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T20:23:04.382Z","etag":null,"topics":["minitest","rails","rspec","stimulus"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henrahmagix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-30T19:03:49.000Z","updated_at":"2025-03-30T20:02:00.000Z","dependencies_parsed_at":"2025-03-30T20:33:31.869Z","dependency_job_id":null,"html_url":"https://github.com/henrahmagix/stimulus_tests","commit_stats":null,"previous_names":["henrahmagix/stimulus_tests"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrahmagix%2Fstimulus_tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrahmagix%2Fstimulus_tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrahmagix%2Fstimulus_tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrahmagix%2Fstimulus_tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henrahmagix","download_url":"https://codeload.github.com/henrahmagix/stimulus_tests/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246523847,"owners_count":20791444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["minitest","rails","rspec","stimulus"],"created_at":"2025-03-31T19:17:32.424Z","updated_at":"2026-04-15T15:43:33.135Z","avatar_url":"https://github.com/henrahmagix.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StimulusTests\n\nTest your Stimulus controllers in Rails!\n\nThis gem provides a route in test environments by which you can render any HTML with an importmap entry point, and assert on it with the usual browser finders and actions.\n\nThis supports the latest minor versions from Rails 6.1 to 8.0. See [Appraisals](/Appraisals).\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"stimulus_tests\", github: \"henrahmagix/stimulus_tests\", group: :test\n```\n\nAnd then execute:\n```shell\n$ bundle\n```\n\nOr install it yourself as:\n```shell\n$ bundle add stimulus_tests --github henrahmagix/stimulus_tests\n```\n\nI'm unsure how to `gem install` this from GitHub source. Unfortunately `gem install` instructions will be unavailable until I publish this on RubyGems.\n\n## Usage\n\nSee also [Examples](#examples). All the code examples here reference the default Stimulus controller made by `bin/rails stimulus:install` named `hello`, which replaces the element's text with `\"Hello World!\"`\n\nFirst, include the DSL and set an `import` in your test setup scope:\n```rb\ninclude StimulusTests::DSL\n\nimport \"application\"\n```\n\nThen call `render_stimulus` before your assertions. It can be called one of two ways:\n```rb\n# 1. With a HTML string.\nrender_stimulus '\u003cp data-controller=\"hello\"\u003eInitial text\u003c/p\u003e'\n\n# 2. With a block that gets evaluated in a View context where you can make use of tag helpers.\n# The return value is used like the HTML string.\nrender_stimulus do\n  content_tag :p, 'Initial text', data: { controller: \"hello\" }\nend\n```\n\nNow you can assert on the browser page, like `assert_text \"Hello World!\"` ✨\n\n\u003cbr\u003e\n\nUnder the hood, `render_stimulus` visits a route defined by this gem (see [Configuration](#configuration)), where the controller action renders `javascript_importmap_tags` with the given `import`, and then the HTML. This is how we get a test browser to load a page with just the JavaScript we need without having to commit such a page to your app.\n\nYou can also call `layout` to configure the layout of the controller defined by this gem:\n```rb\ninclude StimulusTests::DSL\n\nlayout \"application\"\n```\n\nMost of the time you won't need both `layout` and `import`: if you have a layout with your entry point already, you can use that and you don't need to use `import`.\n\nDefining an `import` entry point and _not_ having a layout reduces the dependencies so you can more clearly unit-test your Stimulus controllers.\n\nThey can also be passed into `render_stimulus` to override the previous definitions:\n```rb\nrender_stimulus(layout: \"my_specific_layout\", import: \"controllers\") do\n  '\u003cp data-controller=\"hello\"\u003eInitial text\u003c/p\u003e'\nend\n```\n\n**Note:** if you specify both, and the layout already includes the importmap entry point, then it'll get added twice: this gem always renders the given import into the `\u003chead\u003e`.\n\n### Configuration\n\n```rb\n# config/environments/test.rb\nRails.application.configure do\n  config.stimulus_tests.route_path = \"/_stimulus_tests\" # this is the default\nend\n```\n\n## Examples\n\n### Rails tests\n\n```rb\n# test/system/hello_stimulus_controller_test.rb\nrequire \"application_system_test_case\"\nrequire \"stimulus_tests\"\n\nclass HelloStimulusControllerTest \u003c ApplicationSystemTestCase\n  include StimulusTests::DSL\n\n  layout \"application\"\n  # or\n  # import \"application\"\n\n  test \"runs my controllers\" do\n    render_stimulus \u003c\u003c~HTML\n      \u003cp data-controller=\"hello\"\u003eInitial text\u003c/p\u003e\n    HTML\n\n    assert_text \"Hello World!\"\n  end\nend\n```\n\n### RSpec\n\nRequire this gem in your Rails helper:\n```rb\n# spec/rails_helper.rb\nrequire \"stimulus_tests\"\n```\n\nEvery example in `spec/stimulus`, `spec/features/stimulus`, and `spec/system/stimulus` automatically gets the DSL included.\n\n```rb\n# spec/stimulus/hello_controller_spec.rb\nrequire \"rails_helper\"\n\nRSpec.feature \"Stimulus::HelloController\" do\n  layout \"application\"\n  # or\n  # import \"application\"\n\n  it \"runs my controllers\" do\n    render_stimulus \u003c\u003c~HTML\n      \u003cp data-controller=\"hello\"\u003eInitial text\u003c/p\u003e\n    HTML\n\n    assert_text \"Hello World!\"\n  end\nend\n```\n\nYou can setup any other example individually by ensuring the following:\n- `StimulusTests::DSL` is included in the example group.\n- Examples are run with a JavaScript driver.\n\n## Contributing\nPlease do! Issues are 👆 up there, and feel free to submit pull-requests for your ideas.\n\nI can't guarantee when I'll be able to read and respond, sorry.\n\n### Setup\n\n```sh\nbin/appraisal install\n```\n\n### Dev\n\nThere's a custom `bin/rails` script that uses the Rails 8 appraisal and proxies to the test/dummy app.\n```sh\nbin/rails server # in the root folder\n```\n\nThe test/dummy app is intentionally sparse: it's just meant to exemplify one simple Stimulus controller to System tests can assert on it.\n\n### Tests\n\nWe have both Minitest and RSpec tests because this gem works with both frameworks.\n\nThis gem's tests are written in Minitest in the `test/` directory. The RSpec tests in `spec/` are only to test the integration of this gem with RSpec.\n\n`bin/test` has been edited to run all tests by default, unless given specific paths.\n\n```sh\nbin/appraisal bin/test\n```\n```sh\nbin/appraisal bin/rspec\n```\n\nTo run all the tests together:\n```sh\nbin/appraisal bin/test \u0026\u0026 bin/appraisal bin/rspec\n```\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrahmagix%2Fstimulus_tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenrahmagix%2Fstimulus_tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrahmagix%2Fstimulus_tests/lists"}