For E2E testing your Rails app without Ruby-based engine, you might need to
- Create a test user with FactoryBot
- Mock external API calls and some methods
- Begin/rollback transactions for each test
This gem provides rack middlewared for such purposes.
Add this line to your application's Gemfile:
group :test do
gem 'e2e_testing_on_rails', github: 'YusukeIwaki/e2e_testing_on_rails'
end
then execute bundle install
.
RAILS_ENV=test bundle exec rails s
Control endpoints are automatically defined.
echo '{ name: "YusukeIwaki", password: "hogehoge" }' | http POST http://localhost:3000/__e2e__/factory_bot/create?name=user
This internally calls FactoryBot.create(:user, name: "YusukeIwaki", password: "hogehoge")
and return the instance as JSON.
{
"id": 123,
"name": "YusukeIwaki",
"created_at": "2023-10-25T15:13:35.712Z",
"updated_at": "2023-10-25T15:13:35.712Z"
}
Just issue BEGIN
and ROLLBACK
. Useful for transactional test.
Allow to evaluate arbitrary Ruby code. Useful for mocking.
echo 'SimpleStub.for_instance_method(ApplicationController, :current_user) { User.last }.apply!' | http POST http://localhost:3000/__e2e__/eval
echo 'SimpleStub.for_instance_method(ApplicationController, :current_user) { User.last }.reset!' | http POST http://localhost:3000/__e2e__/eval
simple_stub would be the best choice for mocking with this method.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the E2eTestingOnRails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.