All Projects → davydovanton → rspec-hanami

davydovanton / rspec-hanami

Licence: MIT license
RSpec Matchers for Hanami

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to rspec-hanami

hanami-shrine
Upload solution for Hanami using Shrine library
Stars: ✭ 28 (-40.43%)
Mutual labels:  hanami
mache
A library for writing cleaner and more expressive acceptance tests using page objects.
Stars: ✭ 40 (-14.89%)
Mutual labels:  rspec
fixturama
Collection of helpers for dealing with fixtures in RSpec
Stars: ✭ 33 (-29.79%)
Mutual labels:  rspec
hanami-api-amazon-aws-lambda
Hanami::API on Amazon AWS Lambda
Stars: ✭ 36 (-23.4%)
Mutual labels:  hanami
saharspec
RSpec sugar to DRY your specs
Stars: ✭ 58 (+23.4%)
Mutual labels:  rspec
givens
Easy test setup without side effects.
Stars: ✭ 22 (-53.19%)
Mutual labels:  rspec
capybara-chromedriver-logger
Enables console.log/error/info output from Javascript feature specs running with Chromedriver
Stars: ✭ 54 (+14.89%)
Mutual labels:  rspec
rspec.tmbundle
Textmate bundle for RSpec.
Stars: ✭ 196 (+317.02%)
Mutual labels:  rspec
turbo tests
Run RSpec tests on multiple cores. Like parallel_tests but with incremental summarized output. Originally extracted from the Discourse and Rubygems source code.
Stars: ✭ 81 (+72.34%)
Mutual labels:  rspec
wisper-rspec
RSpec matchers and stubbing for Wisper
Stars: ✭ 59 (+25.53%)
Mutual labels:  rspec
solr wrapper
Wrap your tests with Solr 5+
Stars: ✭ 22 (-53.19%)
Mutual labels:  rspec
rspec-tap-formatters
TAP Producer for RSpec-3
Stars: ✭ 20 (-57.45%)
Mutual labels:  rspec
bdd
Given/When/Then/And/But output to RSpec and Minitest
Stars: ✭ 33 (-29.79%)
Mutual labels:  rspec
serverspec-extended-types
A set of extended types for ServerSpec 2.x
Stars: ✭ 28 (-40.43%)
Mutual labels:  rspec
Ruby Capstone
A simple web scraper built with Ruby and the Nokogiri gem. It crawls a certain website and gets the prices and other data of cryptocurrencies. Rspec was used for testing.
Stars: ✭ 14 (-70.21%)
Mutual labels:  rspec
j8spec
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.
Stars: ✭ 45 (-4.26%)
Mutual labels:  rspec
database plumber
Find leaky ActiveRecord models in your RSpec tests
Stars: ✭ 13 (-72.34%)
Mutual labels:  rspec
allure-ruby
Allure integrations for Ruby test frameworks
Stars: ✭ 40 (-14.89%)
Mutual labels:  rspec
capybara select2
Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)
Stars: ✭ 48 (+2.13%)
Mutual labels:  rspec
ginkgo4j
A Java BDD Testing Framework (based on RSpec and Ginkgo)
Stars: ✭ 25 (-46.81%)
Mutual labels:  rspec

RSpec::Hanami

Build Status Coverage Status

rspec-hanami is a testing framework for hanami

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'rspec-hanami'
end

And 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

  # ...
end

Capybara

Check 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.new

Please change this line to:

Capybara.app = ::Hanami::Container.new
# or
Capybara.app = ::Hanami::App.new

For more information see this issue

Supported matchers

Request helpers

You can use familiar request helpers like #get, #post, etc. These methods make full hanami app request and return env (array with 3 elements).

For using these helpers include RSpec::Hanami::RequestHelpers to your spec_helper.rb file:

config.include RSpec::Hanami::RequestHelpers

After that you can call any method:

it { expect(get('/')).to be_success }
it { expect(post('/tasks')).to redirect_to('/tasks') }

Controller Specs

have_http_status

Passes if response has a matching HTTP status code.

The following symbolic status codes are allowed:

  • :error
  • :missing
  • :redirect
  • :success
  • Rack::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)

be_success

Passes if response has a not 4xx and 5xx error code.

response = action.call(params)
expect(response).to be_success

redirect_to

Passes if response has a redirect to special url

response = action.call(params)
expect(response).to redirect_to('site.com')

match_in_body

Passes if body matches with argument

response = action.call(params)
expect(response).to match_in_body('Tittle')
expect(response).to match_in_body(/Tittle\s\d+/)

include_json

Passes if json string in the body matches with hash arg

response = action.call(params)
expect(response).to include_json(name: 'Anton')
expect(response).to include_json(user: { name: 'Anton })

Views Specs

have_form_action

Passes if form object has an action

expect(view.form).to     have_form_action('/users')
expect(view.form).to_not have_form_action('/books')

have_method

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)

have_form_field

Passes if form object has a field with wanted params

expect(view.form).to have_form_field(node: 'input', type: 'text', id: 'user-first-name')

Entity specs

Passes if argument type has a matching with type. You can use Hanami::Entity::Types for compare.

have_attribute

Passes if :name has Types::String type:

it { expect(User).to have_attribute(:name, Types::String) }

have_attributes

Passes if :name has Types::String type and :age has Types::Int type:

it { expect(User).to have_attributes(name: Types::String, age: Types::Int) }

Also see

Feature Requests & Bugs

See http://github.com/davydovanton/rspec-hanami/issues

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].