say8425 / rspec-validates_timeliness

Simple RSpec matchers for validates_timeliness

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RSpec::ValidatesTimeliness Build Status

Simple RSpec matchers for validates_timeliness.

Orginal gem has rails 4.2 dependency isssue, but this fokred gem was updated for Rails 5 and 6.

Matchers

  • validates_datetime tests usage of validates_timeliness's validates_datetime.
  • validates_date tests usage of validates_timeliness's validates_date.
  • validates_time tests usage of validates_timeliness's validate_time.

Installation

Add this line to your application's Gemfile:

gem 'rspec-validates_timeliness', github: 'say8425/rspec-validates_timeliness'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-validates_timeliness

Usage

Here is model:

class Person
  include ActiveModel::model

  validates_date :date_of_birth, before: lambda { 18.years.ago }
  validates_time :breakfast_time, is_at: '7:00am'
  validates_time :updated_at, between: ['9:00am', '5:00pm']

  # validates_datetime :start_time, before: :finish_time **[NOT SUPPORT] Method symbol
  # validates_date :created_at, on_or_after: :today      **[NOT SUPPORT] Shorthand
end

And with rspec-validates_timeliness we can now make simple assertions about those models:

require 'spec_helper'

describe Person, type: :model do
  it { is_expected.to validates_date(:date_of_birth).before(lambda { 18.years.ago }) }
  it { is_expected.to validates_date(:date_of_birth).before { 18.years.ago } } # The same as previous example
  it { is_expected.to validates_time(:breakfast_time).is_at('7:00am') }
  it { is_expected.to validates_time(:updated_at).between(['9:00am', '5:00pm']) }
  it { is_expected.to validates_time(:updated_at).on_or_after('9:00am').on_or_before('5:00pm') } # The same as previous example
end

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

Changelog

Release 0.1.1 (Jun 13, 2016)

  • Fix to optimize expected values.

Release 0.1.0 (Jun 12, 2016)

About

Simple RSpec matchers for validates_timeliness

License:MIT License


Languages

Language:Ruby 99.3%Language:Shell 0.7%