项目作者: activeadmin-plugins

项目描述 :
Capybara DSL for fast and easy testing Active Admin applications.
高级语言: Ruby
项目地址: git://github.com/activeadmin-plugins/capybara_active_admin.git
创建时间: 2020-04-05T15:18:13Z
项目社区:https://github.com/activeadmin-plugins/capybara_active_admin

开源协议:MIT License

下载


Capybara Active Admin

Build Status Gem Version Downloads License: MIT

Capybara DSL for fast and easy testing Active Admin applications.

Check out our docs at activeadmin-plugins.github.io/capybara_active_admin

Installation

Add this line to your application’s Gemfile:

  1. group :test do
  2. gem 'capybara_active_admin'
  3. end

And then execute:

  1. $ bundle install

Or install it yourself as:

  1. $ gem install capybara_active_admin

Note: capybara_active_admin should be required after capybara.

Usage

rails_helper.rb

  1. require 'capybara/active_admin/rspec'

spec/system/users_spec.rb

  1. RSpec.describe 'Users', js: true do
  2. subject do
  3. visit admin_users_path
  4. end
  5. let!(:john) { User.create!(full_name: 'John Doe') }
  6. let!(:jane) { User.create!(full_name: 'Jane Air') }
  7. it 'have john and jane in users table' do
  8. subject
  9. expect(page).to have_action_item('New User')
  10. expect(page).to_not have_action_item('Edit User')
  11. within_table_for('users') do
  12. expect(page).to have_table_row(count: 2)
  13. expect(page).to have_table_cell('John Doe')
  14. within_table_row(id: john.id) do
  15. expect(page).to have_table_cell('John Doe', row_id: john.id)
  16. expect(page).to have_table_cell('John Doe', row_id: john.id, col_name: 'Full Name')
  17. expect(page).to_not have_table_cell('John Doe', row_id: john.id, col_name: 'Id')
  18. end
  19. within_table_row(id: jane.id) do
  20. expect(page).to_not have_table_cell('John Doe')
  21. expect(page).to_not have_table_cell('John Doe', col_name: 'Full Name')
  22. end
  23. end
  24. end
  25. it 'creates user' do
  26. subject
  27. click_action_item('New User')
  28. expect(page).to have_current_path(new_admin_user_path)
  29. within_form_for(User) do
  30. fill_in 'Full name', with: 'Johny Cage'
  31. click_submit 'Create User'
  32. end
  33. expect(page).to have_flash_message('User was successfully created.', type: :notice)
  34. user = User.last!
  35. expect(page).to have_current_path admin_user_path(user.id)
  36. expect(User.count).to eq(1)
  37. expect(user).to have_attributes(full_name: 'Johny Cage')
  38. end
  39. end

See spec/support for more user examples.
See capybara/active_admin/test_helpers.rb for available DSL methods.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/activeadmin-plugins/capybara_active_admin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Capybara::ActiveAdmin project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Notes

Project uses Keep a Changelog convention.
Project adheres to Semantic Versioning.