├── .gitignore
├── .rspec
├── .rubocop.yml
├── .travis.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
├── console
└── setup
├── capybara_active_admin.gemspec
├── docs
├── .vuepress
│ ├── config.js
│ ├── public
│ │ └── .keep
│ └── styles
│ │ └── index.styl
├── README.md
└── guide
│ └── README.md
├── lib
├── capybara
│ ├── active_admin.rb
│ └── active_admin
│ │ ├── actions.rb
│ │ ├── actions
│ │ ├── attributes_table.rb
│ │ ├── form.rb
│ │ ├── layout.rb
│ │ └── table.rb
│ │ ├── finders.rb
│ │ ├── finders
│ │ ├── attributes_table.rb
│ │ ├── form.rb
│ │ ├── layout.rb
│ │ └── table.rb
│ │ ├── matchers.rb
│ │ ├── matchers
│ │ ├── attributes_table.rb
│ │ ├── form.rb
│ │ ├── layout.rb
│ │ └── table.rb
│ │ ├── rspec.rb
│ │ ├── selectors.rb
│ │ ├── selectors
│ │ ├── attributes_table.rb
│ │ ├── form.rb
│ │ ├── layout.rb
│ │ └── table.rb
│ │ ├── test_helpers.rb
│ │ ├── util.rb
│ │ └── version.rb
└── capybara_active_admin.rb
├── package.json
├── spec
├── dummy
│ ├── assets
│ │ ├── active_admin.js
│ │ └── active_admin.scss
│ ├── log
│ │ └── .keep
│ └── test_application.rb
├── lib
│ └── capybara_active_admin_spec.rb
├── rails_helper.rb
└── system
│ ├── business_employee_show_spec.rb
│ ├── business_employees_index_spec.rb
│ ├── users_index_spec.rb
│ └── users_new_spec.rb
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /_yardoc/
4 | /coverage/
5 | /doc/
6 | /pkg/
7 | /spec/reports/
8 | /tmp/
9 | /spec/dummy/tmp/
10 | /spec/dummy/log/*.log
11 |
12 | # rspec failure tracking
13 | .rspec_status
14 |
15 | Gemfile.lock
16 |
17 | # docs
18 | /docs/.vuepress/dist/
19 | /docs/.vuepress/public/api/
20 | /node_modules/
21 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --format documentation
2 | --color
3 | --require rails_helper
4 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | AllCops:
2 | DisplayCopNames: true
3 | TargetRubyVersion: 2.3
4 | Exclude:
5 | - vendor/**/*
6 | - tmp/**/*
7 | - docs/**/*
8 |
9 | # Capybara/RSpec uses have_ had_ as name convention for matchers.
10 | Naming/PredicateName:
11 | Enabled: false
12 |
13 | Lint/RaiseException:
14 | Enabled: true
15 |
16 | Lint/StructNewOverride:
17 | Enabled: true
18 |
19 | Layout/LineLength:
20 | Max: 180
21 |
22 | Style/SymbolArray:
23 | EnforcedStyle: brackets
24 |
25 | Style/Lambda:
26 | EnforcedStyle: literal
27 |
28 | Naming/MethodParameterName:
29 | AllowedNames:
30 | - id
31 |
32 | Style/HashEachMethods:
33 | Enabled: true
34 |
35 | Style/HashTransformKeys:
36 | Enabled: true
37 |
38 | Style/HashTransformValues:
39 | Enabled: true
40 |
41 | Style/Documentation:
42 | Enabled: false
43 |
44 | Metrics/PerceivedComplexity:
45 | Enabled: false
46 |
47 | Metrics/MethodLength:
48 | Enabled: false
49 |
50 | Metrics/AbcSize:
51 | Enabled: false
52 |
53 | Metrics/ModuleLength:
54 | Enabled: false
55 |
56 | Metrics/BlockLength:
57 | Enabled: false
58 |
59 | Metrics/ClassLength:
60 | Enabled: false
61 |
62 | Metrics/CyclomaticComplexity:
63 | Enabled: false
64 |
65 | Layout/MultilineOperationIndentation:
66 | Enabled: false
67 |
68 | Layout/FirstHashElementIndentation:
69 | Enabled: false
70 |
71 | Layout/FirstArrayElementIndentation:
72 | Enabled: false
73 |
74 | Layout/FirstArgumentIndentation:
75 | Enabled: false
76 |
77 | Layout/ClosingParenthesisIndentation:
78 | Enabled: false
79 |
80 | Layout/ArgumentAlignment:
81 | Enabled: false
82 |
83 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # test config on https://config.travis-ci.com/explore
3 | language: ruby
4 | cache: bundler
5 | before_install:
6 | - gem install bundler -v 2.2.32
7 | stages:
8 | - test
9 | - deploy
10 | jobs:
11 | include:
12 | - name: "Test Ruby-3.0.3 Rails-6.1"
13 | stage: test
14 | rvm: 3.0.3
15 | env: RAILS_VERSION="~> 6.1"
16 | before_script: bundle install
17 | script: bundle exec rake default
18 | - name: "Test Ruby-2.5.7 Rails-6.0"
19 | stage: test
20 | rvm: 2.5.7
21 | env: RAILS_VERSION="~> 6.0"
22 | before_script: bundle install
23 | script: bundle exec rake default
24 | - name: "Test Ruby-2.5.7 Rails-5.2"
25 | stage: test
26 | rvm: 2.5.7
27 | env: RAILS_VERSION="~> 5.2"
28 | before_script: bundle install
29 | script: bundle exec rake default
30 | - name: "Test Ruby-2.3.8 Rails-5.2"
31 | stage: test
32 | rvm: 2.3.8
33 | env: RAILS_VERSION="~> 5.2"
34 | before_script: bundle install
35 | script: bundle exec rake default
36 | - name: "Deploy documentation"
37 | stage: deploy
38 | before_script: yarn install
39 | script:
40 | - bundle exec rake yard
41 | - yarn docs:build
42 | deploy:
43 | provider: pages
44 | edge: true
45 | verbose: true
46 | cleanup: false
47 | local_dir: docs/.vuepress/dist
48 | token: $GITHUB_TOKEN
49 | keep_history: true
50 | on:
51 | branch: master
52 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | ## [Unreleased]
8 |
9 | ## [0.3.3] - 2020-04-17
10 | ### Changed
11 | - `batch_action_selector`, `click_batch_action` finds element by link text
12 |
13 | ### Added
14 | - `select_table_row`, `open_batch_action_menu` actions
15 | - `have_batch_action` matcher
16 | - tests for batch actions
17 |
18 | ## [0.3.2] - 2020-04-16
19 | ### Changed
20 | - remove model_name from table related DSL arguments
21 | - improve API
22 |
23 | ## [0.3.1] - 2020-04-15
24 | ### Added
25 | - `within_attribute_row` finder
26 |
27 | ### Removed
28 | - `find_input` finder
29 | - `have_input`, `have_no_input` matchers
30 | - `input_selector` selector
31 |
32 | ## [0.3.0] - 2020-04-15
33 | ### Added
34 | - implement DSL for tabs, batch actions, modal dialog, attributes table, panel, sidebar, footer
35 | - improve form DSL
36 |
37 | ## [0.2.1] - 2020-04-14
38 | ### Fixed
39 | - `table_selector`, `within_table_for` incorrect resource name
40 |
41 | ### Changed
42 | - `table_selector` receives 2 arguments
43 | - `within_table_for` receives 2 arguments
44 | - `current_table_name` renamed to `current_table_model_name`
45 | - `table_row_selector` can receive modal class as model name
46 |
47 | # Added
48 | - `have_table` matcher
49 | - add tests for table with namespaced resource class and multi-word resource name
50 |
51 | ## [0.2.0] - 2020-04-14
52 | ### Changed
53 | - rename `have_table_col` to `have_table_cell`
54 | - change options of `have_table_cell`
55 | - change options of `have_table_row`
56 | - refactor modules hierarchy: split DSL into selectors, finders, matchers and actions
57 |
58 | ### Added
59 | - form DSL
60 | - changelog
61 | - follow semver
62 |
63 | ## [0.1.0] - 2020-04-14
64 | ### Added
65 | - travic CI
66 | - rubocop
67 | - capybara DSL to check page title, action items, table columns/rows
68 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | nationality, personal appearance, race, religion, or sexual identity and
10 | orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at senid231@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at [https://contributor-covenant.org/version/1/4][version]
72 |
73 | [homepage]: https://contributor-covenant.org
74 | [version]: https://contributor-covenant.org/version/1/4/
75 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | # Specify your gem's dependencies in capybara_active_admin.gemspec
6 | gemspec
7 |
8 | gem 'capybara'
9 | gem 'selenium-webdriver'
10 | # https://github.com/mattheworiordan/capybara-screenshot/issues/225#issuecomment-409407825
11 | gem 'cuprite'
12 | gem 'puma'
13 | gem 'rake', '~> 12.0'
14 | gem 'rspec-rails', '~> 4.0'
15 | gem 'rubocop', '~> 0.81.0', require: false
16 | gem 'yard', require: false
17 |
18 | gem 'activeadmin', ENV.fetch('ACTIVE_ADMIN_VERSION', '~> 2.0'), require: false
19 | gem 'rails', ENV.fetch('RAILS_VERSION', '6.0.0')
20 |
21 | # responders 3 drops ruby 2.3 support
22 | if RUBY_VERSION =~ /^2\.3/
23 | gem 'responders', '~> 2.4'
24 | else
25 | gem 'responders' # rubocop:disable Bundler/DuplicatedGem
26 | end
27 |
28 | gem 'sassc-rails', '2.1.2'
29 | gem 'sprockets', '3.7.2'
30 | gem 'sqlite3'
31 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020 Denis Talakevich
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Capybara Active Admin
2 |
3 | [](https://travis-ci.com/activeadmin-plugins/capybara_active_admin) [](https://badge.fury.io/rb/capybara_active_admin) [](https://rubygems.org/gems/capybara_active_admin) [](https://opensource.org/licenses/MIT)
4 |
5 | Capybara DSL for fast and easy testing Active Admin applications.
6 |
7 | Check out our docs at [activeadmin-plugins.github.io/capybara_active_admin](https://activeadmin-plugins.github.io/capybara_active_admin)
8 |
9 | ## Installation
10 |
11 | Add this line to your application's Gemfile:
12 |
13 | ```ruby
14 | group :test do
15 | gem 'capybara_active_admin'
16 | end
17 | ```
18 |
19 | And then execute:
20 |
21 | $ bundle install
22 |
23 | Or install it yourself as:
24 |
25 | $ gem install capybara_active_admin
26 |
27 | **Note: `capybara_active_admin` should be required after `capybara`.**
28 |
29 | ## Usage
30 |
31 | `rails_helper.rb`
32 | ```ruby
33 | require 'capybara/active_admin/rspec'
34 | ```
35 |
36 | `spec/system/users_spec.rb`
37 | ```ruby
38 | RSpec.describe 'Users', js: true do
39 | subject do
40 | visit admin_users_path
41 | end
42 |
43 | let!(:john) { User.create!(full_name: 'John Doe') }
44 | let!(:jane) { User.create!(full_name: 'Jane Air') }
45 |
46 | it 'have john and jane in users table' do
47 | subject
48 |
49 | expect(page).to have_action_item('New User')
50 | expect(page).to_not have_action_item('Edit User')
51 |
52 | within_table_for('users') do
53 | expect(page).to have_table_row(count: 2)
54 | expect(page).to have_table_cell('John Doe')
55 |
56 | within_table_row(id: john.id) do
57 | expect(page).to have_table_cell('John Doe', row_id: john.id)
58 | expect(page).to have_table_cell('John Doe', row_id: john.id, col_name: 'Full Name')
59 | expect(page).to_not have_table_cell('John Doe', row_id: john.id, col_name: 'Id')
60 | end
61 |
62 | within_table_row(id: jane.id) do
63 | expect(page).to_not have_table_cell('John Doe')
64 | expect(page).to_not have_table_cell('John Doe', col_name: 'Full Name')
65 | end
66 | end
67 | end
68 |
69 | it 'creates user' do
70 | subject
71 |
72 | click_action_item('New User')
73 | expect(page).to have_current_path(new_admin_user_path)
74 |
75 | within_form_for(User) do
76 | fill_in 'Full name', with: 'Johny Cage'
77 | click_submit 'Create User'
78 | end
79 |
80 | expect(page).to have_flash_message('User was successfully created.', type: :notice)
81 | user = User.last!
82 | expect(page).to have_current_path admin_user_path(user.id)
83 |
84 | expect(User.count).to eq(1)
85 | expect(user).to have_attributes(full_name: 'Johny Cage')
86 | end
87 | end
88 | ```
89 |
90 | See `spec/support` for more user examples.
91 | See `capybara/active_admin/test_helpers.rb` for available DSL methods.
92 |
93 | ## Development
94 |
95 | 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.
96 |
97 | 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](https://rubygems.org).
98 |
99 | ## Contributing
100 |
101 | 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](https://github.com/activeadmin-plugins/capybara_active_admin/blob/master/CODE_OF_CONDUCT.md).
102 |
103 | ## License
104 |
105 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
106 |
107 | ## Code of Conduct
108 |
109 | Everyone interacting in the Capybara::ActiveAdmin project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/activeadmin-plugins/capybara_active_admin/blob/master/CODE_OF_CONDUCT.md).
110 |
111 | ## Notes
112 |
113 | Project uses [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
114 | Project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
115 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'bundler/gem_tasks'
4 | require 'rspec/core/rake_task'
5 | require 'rubocop/rake_task'
6 | require 'yard'
7 | require 'yard/rake/yardoc_task'
8 |
9 | RSpec::Core::RakeTask.new(:spec)
10 | RuboCop::RakeTask.new(:rubocop)
11 | YARD::Rake::YardocTask.new(:yard) do |task|
12 | task.options += [
13 | %(--output-dir=./docs/.vuepress/public/api/),
14 | %(--title=Capybara Active Admin API Reference)
15 | ]
16 | end
17 |
18 | task default: [:rubocop, :spec]
19 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require 'bundler/setup'
5 | require 'capybara_active_admin'
6 |
7 | # You can add fixtures and/or initialization code here to make experimenting
8 | # with your gem easier. You can also use a different console, if you like.
9 |
10 | # (If you use this, don't forget to add pry to your Gemfile!)
11 | # require "pry"
12 | # Pry.start
13 |
14 | require 'irb'
15 | IRB.start(__FILE__)
16 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/capybara_active_admin.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative 'lib/capybara/active_admin/version'
4 |
5 | Gem::Specification.new do |spec|
6 | spec.name = 'capybara_active_admin'
7 | spec.version = Capybara::ActiveAdmin::VERSION
8 | spec.authors = ['Denis Talakevich']
9 | spec.email = ['senid231@gmail.com']
10 |
11 | spec.summary = 'Capybara DSL for fast and easy testing Active Admin applications.'
12 | spec.description = 'Capybara DSL for fast and easy testing Active Admin applications.'
13 | spec.homepage = 'https://github.com/active_admin_plugins/capybara_active_admin'
14 | spec.license = 'MIT'
15 | spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16 |
17 | spec.metadata['homepage_uri'] = spec.homepage
18 | spec.metadata['source_code_uri'] = spec.homepage
19 | spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20 |
21 | # Specify which files should be added to the gem when it is released.
22 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23 | spec.files = Dir.chdir(File.expand_path(__dir__)) do
24 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25 | end
26 | spec.bindir = 'exe'
27 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28 | spec.require_paths = ['lib']
29 |
30 | spec.add_dependency 'activeadmin'
31 | # spec.add_dependency 'devise'
32 | spec.add_dependency 'rspec', '~> 3.0'
33 | end
34 |
--------------------------------------------------------------------------------
/docs/.vuepress/config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | title: 'Capybara Active Admin',
3 | description: 'Capybara DSL for fast and easy testing Active Admin applications.',
4 | base: '/capybara_active_admin/',
5 | themeConfig: {
6 | nav: [
7 | { text: 'Guide', link: '/guide/' },
8 | { text: 'API Reference', link: '/api/', target: '_blank' },
9 | { text: 'GitHub', link: 'https://github.com/activeadmin-plugins/capybara_active_admin' }
10 | ]
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/docs/.vuepress/public/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activeadmin-plugins/capybara_active_admin/d2cdc2c0a5478d4ee1afb30f3465c7be3b760a86/docs/.vuepress/public/.keep
--------------------------------------------------------------------------------
/docs/.vuepress/styles/index.styl:
--------------------------------------------------------------------------------
1 | div.theme-default-content:not(.custom) {
2 | max-width: 75%;
3 | }
4 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | home: true
3 | actionText: Get Started →
4 | actionLink: /guide/
5 | footer: MIT Licensed | Copyright © 2020-present Denis Talakevich
6 | ---
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Fast Test Writing
15 |
Allow to focus on what you want to test instead of how to do it.
16 |
17 |
18 |
Simplicity
19 |
Following Ruby an Capybara naming conventions allows easily to read and understand tests code.
20 |
21 |
22 |
Customizable
23 |
You can easy extend, customize, and mix parts of library to fit your needs.
24 |
25 |
26 |
27 | ### As Easy as 1, 2, 3
28 |
29 | ```bash
30 | # install
31 | gem install capybara_active_admin
32 | # OR echo "gem 'capybara_active_admin', group: :test, require: false" >> Gemfile
33 | ```
34 | ```ruby
35 | # require in in rspec/rails_helper.rb
36 | require 'capybara/active_admin/rspec'
37 | ```
38 |
39 | ::: warning COMPATIBILITY NOTE
40 | requires Ruby >= 2.3.
41 | :::
42 |
--------------------------------------------------------------------------------
/docs/guide/README.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 |
4 |
5 | `Capybara::ActiveAdmin` created to write tests as fast as `ActiveAdmin` resource which they are test.
6 |
7 | ## Getting Started
8 |
9 | ### Installation
10 |
11 | ```ruby
12 | # Gemfile
13 |
14 | gem 'capybara_active_admin', group: :test, require: false
15 | ```
16 |
17 | ```ruby
18 | # spec/rails_helper.rb
19 |
20 | # after require 'rspec' or 'rspec/rails'
21 | require 'capybara/active_admin/rspec'
22 | ```
23 |
24 | ### Usage
25 |
26 | For example we have such database table
27 | ```ruby
28 | create_table :users do |t|
29 | t.string :full_name
30 | t.timestamps
31 | end
32 | ```
33 | And such `ActiveRecord` model
34 | ```ruby
35 | class User < ActiveRecord::Base
36 | validates :full_name, presence: true
37 | end
38 | ```
39 | And there is our `ActiveAdmin` resource
40 | ```ruby
41 | ActiveAdmin.register User do
42 | permit_params :full_name
43 | end
44 | ```
45 |
46 | Our test can look like below
47 | ```ruby
48 | # spec/system/users_spec.rb
49 |
50 | RSpec.describe 'Users' do
51 |
52 | describe 'index page' do
53 | subject do
54 | visit admin_users_path
55 | end
56 |
57 | it 'have no table' do
58 | subject
59 |
60 | expect(page).to have_text('There are no Users yet.')
61 | expect(page).to have_action_item('New User')
62 | expect(page).to_not have_action_item('Edit User')
63 | expect(page).to_not have_table
64 | end
65 |
66 | context 'with users' do
67 | let!(:users) do
68 | [
69 | User.create!(full_name: 'John Doe'),
70 | User.create!(full_name: 'Jane Air')
71 | ]
72 | end
73 |
74 | it 'have correct table rows' do
75 | subject
76 |
77 | # you can check that table is visible on page
78 | expect(page).to have_table
79 |
80 | # checkout data within table,
81 | # same as `within(table_selector) do`
82 | within_table_for do
83 | # check how many rows in table (tr)
84 | expect(page).to have_table_row(count: 2)
85 | # or cells (td)
86 | expect(page).to have_table_cell(count: 10)
87 | # or check cell of specific column contain specific value,
88 | # accepts same options as `have_selector`, such as :text, :exact_text, :count, etc.
89 | expect(page).to have_table_cell(text: 'John Doe', column: 'Full Name')
90 |
91 | # we can check data inside specific row by record id,
92 | # or we can find it by index in table `within_table_row(index: 0) do`.
93 | within_table_row(id: users.first.id) do
94 | # default columns for users table are id, full_name, created_at, updated_at, actions.
95 | expect(page).to have_table_cell(count: 5)
96 | expect(page).to have_table_cell(text: 'John Doe')
97 | # or you can write
98 | expect(page).to have_table_cell(text: 'John Doe', column: 'Full Name')
99 | # negate matcher
100 | expect(page).to_not have_table_cell(text: 'John Doe', column: 'Id')
101 | end
102 |
103 | within_table_row(id: users.second.id) do
104 | expect(page).to have_table_cell(text: users.second.id, column: 'Id')
105 | expect(page).to have_table_cell(text: 'Jane Air', column: 'Full Name')
106 | expect(page).to_not have_table_cell(text: 'John Doe')
107 | end
108 | end
109 | end
110 | end
111 | end
112 | end
113 | ```
114 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'capybara/active_admin/version'
4 | require 'capybara/active_admin/util'
5 | require 'capybara/active_admin/selectors'
6 | require 'capybara/active_admin/finders'
7 | require 'capybara/active_admin/matchers'
8 | require 'capybara/active_admin/actions'
9 | require 'capybara/active_admin/test_helpers'
10 |
11 | module Capybara
12 | module ActiveAdmin
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/actions.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'capybara/active_admin/actions/layout'
4 | require 'capybara/active_admin/actions/table'
5 | require 'capybara/active_admin/actions/attributes_table'
6 | require 'capybara/active_admin/actions/form'
7 |
8 | module Capybara
9 | module ActiveAdmin
10 | module Actions
11 | # Actions are interactions with page that change something (click button, fill field, etc).
12 | # Good method names starts with *click_*, *scroll_*, *fill_*, *clear_*, *switch_*, *open_*.
13 |
14 | include Actions::Layout
15 | include Actions::Table
16 | include Actions::AttributesTable
17 | include Actions::Form
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/actions/attributes_table.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Capybara
4 | module ActiveAdmin
5 | module Actions
6 | module AttributesTable
7 | # todo
8 | end
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/actions/form.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Capybara
4 | module ActiveAdmin
5 | module Actions
6 | module Form
7 | def click_submit(value, options = {})
8 | selector = form_submit_selector(value)
9 | find(selector, **options).click
10 | end
11 |
12 | def fill_in_file(label, options = {})
13 | path = options.delete(:with)
14 | attach_file(label, path)
15 | end
16 | end
17 | end
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/actions/layout.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Capybara
4 | module ActiveAdmin
5 | module Actions
6 | # Actions for common Active Admin components.
7 | module Layout
8 | def click_action_item(title, options = {})
9 | within(action_items_container_selector) do
10 | click_link(title, **options)
11 | end
12 | end
13 |
14 | def switch_tab(tab_name, options = {})
15 | opts = Util.options_with_text(tab_name, options)
16 | find(tab_header_link_selector, **opts).click
17 | end
18 |
19 | def click_batch_action(title, exact: true)
20 | open_batch_action_menu
21 | within(dropdown_list_selector) do
22 | selector = batch_action_selector
23 | opts = Util.options_with_text(title, exact: exact)
24 | find(selector, **opts).click
25 | end
26 | end
27 |
28 | def open_batch_action_menu
29 | return if find_all(dropdown_list_selector).present?
30 |
31 | find(batch_actions_button_selector).click
32 | end
33 |
34 | def confirm_modal_dialog
35 | within_modal_dialog { click_button 'OK' }
36 | end
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/actions/table.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Capybara
4 | module ActiveAdmin
5 | module Actions
6 | module Table
7 | def select_table_row(id: nil, index: nil)
8 | raise ArgumentError, "can't use both :id and :index" if id && index
9 | raise ArgumentError, 'must provide :id or :index' if id.nil? && index.nil?
10 |
11 | if id
12 | find("input#batch_action_item_#{id}").click
13 | return
14 | end
15 |
16 | selector = %(input[id^="batch_action_item_"])
17 | find_all(selector, minimum: index + 1)[index].click
18 | end
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/finders.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'capybara/active_admin/finders/layout'
4 | require 'capybara/active_admin/finders/table'
5 | require 'capybara/active_admin/finders/attributes_table'
6 | require 'capybara/active_admin/finders/form'
7 |
8 | module Capybara
9 | module ActiveAdmin
10 | # Finders are methods that find DOM element(s) or change current scope to node element.
11 | #
12 | # Find element(s) method names should start with *find_*.
13 | #
14 | # Change current scope method names should start with *within_*.
15 | module Finders
16 | include Finders::Layout
17 | include Finders::Table
18 | include Finders::AttributesTable
19 | include Finders::Form
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/capybara/active_admin/finders/attributes_table.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Capybara
4 | module ActiveAdmin
5 | module Finders
6 | # Finder methods for ActiveAdmin attributes_table_for can be found here.
7 | # @see Capybara::ActiveAdmin::Finders base finders module.
8 | module AttributesTable
9 | # Calls block within attributes table.
10 | # @param model [Class