It is a testing framework for BDD (Behavior Driven Development) in ruby.
In addition to being able to simulate the browser operation of a Web application, the browser operation can be intuitively described using capybara's DSL. You can actually operate a browser or a Handless browser (without GUI)
It is a gem that supports the creation of test data. Test data can be easily prepared and can be called from the test and used.
Add gem to Gemfile At this time, fill in the block of the test group By filling in the group, the gem will be enabled only in the test environment.
Gemfile
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'webdrivers'
gem 'rspec-rails'
end
python
$ bundle
After executing the bundle, execute the following generate command to create the directories and configuration files required for RSpec.
python
$ bin/rails g rspec:install
After this, the test directory prepared by Rails by default is unnecessary, so delete it.
python
$ rm -r ./test
Set up Handless Chrome in your browser. At this time, an error will occur and can be resolved by referring to the link below. https://takuyakou.hatenablog.com/entry/2019/09/12/192755
spec_helper.rb
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :selenium_chrome_headless
end
...abridgement
end
Add factory_bot_rails to Gemfile and run bundle.
Gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'factory_bot_rails'
end
Now you can test from the spec directory that was created without Rails App.
Recommended Posts