Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/izumin5210/rspec-validator_spec_helper

Provide dummy class for validator spec
https://github.com/izumin5210/rspec-validator_spec_helper

rspec ruby

Last synced: 4 months ago
JSON representation

Provide dummy class for validator spec

Awesome Lists containing this project

README

        

# RSpec::ValidatorSpecHelper

[![Build Status](https://travis-ci.org/izumin5210/rspec-validator_spec_helper.svg?branch=master)](https://travis-ci.org/izumin5210/rspec-validator_spec_helper)

Provide dummy class for validator spec

## Installation

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

```ruby
gem 'rspec-validator_spec_helper'
```

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

```ruby
# 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

```ruby
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) { '[email protected]' }
it { is_expected.to be_valid }
end

context 'with strict option' do
let(:options) { { strict: true } }
let(:value) { '[email protected]' }
it { is_expected.to_not be_valid }
end
end
end
```

### Validator

```ruby
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](http://opensource.org/licenses/MIT).