rspec-hanami is a testing framework for hanami
Add this line to your application's Gemfile:
group :test do
gem 'rspec-hanami'
endAnd then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-hanami
After that require gem to spec_helper.rb and include matchers to rspec:
require 'rspec/hanami'
RSpec.configure do |config|
config.include RSpec::Hanami::Matchers
# ...
endCheck your spec/features_helper.rb and spec/support/Capybara.rb files. If you find something like this:
Capybara.app = Hanami::Container.new
# or
Capybara.app = Hanami::App.newPlease change this line to:
Capybara.app = ::Hanami::Container.new
# or
Capybara.app = ::Hanami::App.new
For more information see this issue
You can use familiar request helpers like #get, #post, etc.
This methods make full hanami app request and retutn env (array with 3 elements).
For using this helpers include RSpec::Hanami::RequestHelpers to your `spec_helper.rb' file:
config.include RSpec::Hanami::RequestHelpersAfter that you can call any method:
it { expect(get('/')).to be_success }
it { expect(post('/tasks')).to redirect_to('/tasks') }Passes if response has a matching HTTP status code.
The following symbolic status codes are allowed:
:error:missing:redirect:successRack::Utils::SYMBOL_TO_STATUS_CODE
response = action.call(params)
expect(response).to have_http_status(404)
expect(response).to have_http_status(:created)
expect(response).to have_http_status(:success)
expect(response).to have_http_status(:error)
expect(response).to have_http_status(:missing)
expect(response).to have_http_status(:redirect)Passes if response has a not 4xx and 5xx error code.
response = action.call(params)
expect(response).to be_successPasses if response has a redirect to special url
response = action.call(params)
expect(response).to redirect_to('site.com')Passes if body match with argument
response = action.call(params)
expect(response).to match_in_body('Tittle')
expect(response).to match_in_body(/Tittle\s\d+/)Passes if form object has a action
expect(view.form).to have_action('/users')
expect(view.form).to_not have_action('/books')Passes if form object has a method
expect(view.form).to have_method('POST')
expect(view.form).to have_method(:post)
expect(view.form).to_not have_method(:put)Passes if form object has a field with wanted params
expect(view.form).to have_field(node: input, type: 'text', id: 'user-first-name')- https://github.com/rspec/rspec
- https://github.com/rspec/rspec-core
- https://github.com/rspec/rspec-expectations
- https://github.com/rspec/rspec-mocks
See http://github.com/davydovanton/rspec-hanami/issues
The gem is available as open source under the terms of the MIT License.