No commit activity in last 3 years
No release in over 3 years
Provide dummy class for validator spec
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

 Project Readme

RSpec::ValidatorSpecHelper

Build Status

Provide dummy class for validator spec

Installation

Add this line to your application's Gemfile, then execute bundle install.

gem 'rspec-validator_spec_helper'

Then include Rspec::ValidatorSpecHelper into your RSpec.configuration.

# spec/rails_helper.rb or spec/spec_helper.rb
RSpec.configure do |config|

  config.include RSpec::ValidatorSpecHelper, type: :validator

end

Usage

RSpec::ValidatorSpecHelper provides some let and subject to your example groups.

EachValidator

describe EmailValidator, type: :validator do
  describe '#validate_each' do
    context 'with invalid format address' do
      let(:value) { 'kokoro.pyonpyon' }
      it { is_expected.to_not be_valid }
    end

    context 'with valid format address' do
      let(:value) { 'kokoro.pyonpyon@example.com' }
      it { is_expected.to be_valid }
    end

    context 'with strict option' do
      let(:options) { { strict: true } }
      let(:value) { 'kokoro..pyonpyon@example.com' }
      it { is_expected.to_not be_valid }
    end
  end
end

Validator

describe NotOverlappedValidator, type: :validator do
  let(:attribute_names) { [:begin_at, :end_at] }
  let(:begin_at) { Time.parse("2014-12-24T12:00:00+09:00") }

  describe '#validate' do
    context 'when end_at is overlapped' do
      let(:end_at) { Time.parse("2014-12-24T09:00:00+09:00") }
      it { is_expected.to_not be_valid }
    end

    context 'when end_at is not overlapped' do
      let(:end_at) { Time.parse("2014-12-24T19:00:00+09:00") }
      it { is_expected.to be_valid }
    end

    context 'with allow_same_time option' do
      let(:options) { { allow_same_time: true } }
      let(:end_at) { begin_at }
      it { is_expected.to be_valid }
    end
  end
end

License

RSpec::ValidatorSpecHelper is licensed under MIT-LICENSE.