0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Making tests easy on the fingers and eyes, but on hanami.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
~> 3.4.0

Runtime

 Project Readme

shoulda-hanami

Gem Version Build Status Code Climate Test Coverage Dependency Status Inline docs

Making tests easy on the fingers and eyes, but on hanami.

Installation

Add this line to your application's Gemfile:

gem 'shoulda-hanami'

And then execute:

$ bundle

Or install it yourself as:

$ gem install shoulda-hanami

Configure

Create file spec/support/shoulda_hanami.rb with:

RSpec.configure do |config|
  config.include Shoulda::Hanami::Matchers
end

Usage

Entity

class Person
  include Hanami::Validations

  validations do
    required(:email)    { format?(/@/) }
    required(:name)     { size?(5..50) }
    required(:password) { size?(10) }
    required(:state)    { included_in?(%w(PR SC SP)) }
    required(:year)     { included_in?(1979..1990) }
  end
end

Spec

# allow_value
it { is_expected.to allow_value("leo@nospam.org").for(:email) }
it { is_expected.to_not allow_value('leo-at-nospam.org').for(:email) }

# presence
it { is_expected.to validate_presence_of(:email) }

# size
it { is_expected.to validate_length_of(:name).is_at_least(5).is_at_most(50) }
it { is_expected.to validate_length_of(:password).is_equal_to(10) }

# inclusion
it { is_expected.to validate_inclusion_of(:state).in_array(%w(PR SC SP)) }
it { is_expected.to validate_inclusion_of(:year).in_array(1979..1990) }

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

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