Last active
August 21, 2018 17:51
-
-
Save yihyang/27569332d1b0bcfda05b119005e80d6f to your computer and use it in GitHub Desktop.
Rspec testing validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| class Validatable | |
| include ActiveModel::Validations | |
| attr_accessor :data | |
| validates :data, lead_data: true | |
| end | |
| describe DataValidator do | |
| subject { Validatable.new } | |
| before { subject.data = data } | |
| context 'valid data' do | |
| let(:data) do | |
| { 'product' => 'Valid Product' } | |
| end | |
| it { is_expected.to be_valid } | |
| end | |
| context 'contains invalid data' do | |
| let(:data) do | |
| { 'product' => 'Invalid Product' } | |
| end | |
| it { is_expected.to be_invalid } | |
| end | |
| context 'empty data' do | |
| let(:data) { {} } | |
| it { is_expected.to be_invalid } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment