-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wired up a framework for testing with rspec, including 2 POC specs
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--order random |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'active_model' if Gem.loaded_specs.keys.include?('activemodel') | ||
|
||
RSpec::Matchers.define :have_errors_on_email do | ||
match do |actual| | ||
expect(actual).not_to be_nil, "#{actual} should not be nil" | ||
expect(actual).not_to be_empty, "#{actual} should not be empty" | ||
expect(actual.size).to eq(@reasons.size), "#{actual} should have #{@reasons.size} elements" | ||
@reasons.each do |reason| | ||
reason = "#{"Email " if defined?(ActiveModel)}#{reason}" | ||
expect(actual).to include(reason), "#{actual} should contain #{reason}" | ||
end | ||
end | ||
chain :because do |reason| | ||
(@reasons ||= []) << reason | ||
end | ||
chain :and_because do |reason| | ||
(@reasons ||= []) << reason | ||
end | ||
match_when_negated do |actual| | ||
expect(actual).to (defined?(ActiveModel) ? be_empty : be_nil) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require_relative "spec_helper" | ||
require "validates_email_format_of" | ||
|
||
describe ValidatesEmailFormatOf do | ||
before(:all) do | ||
described_class.load_i18n_locales | ||
I18n.enforce_available_locales = false | ||
end | ||
subject do |example| | ||
if defined?(ActiveModel) | ||
user = Class.new do | ||
def initialize(email) | ||
@email = email | ||
end | ||
attr_reader :email | ||
include ActiveModel::Validations | ||
validates_email_format_of :email, example.example_group_instance.options | ||
end | ||
example.example_group_instance.class::User = user | ||
user.new(example.example_group_instance.email).tap(&:valid?).errors.full_messages | ||
else | ||
ValidatesEmailFormatOf::validate_email_format(email, options) | ||
end | ||
end | ||
let(:options) { {} } | ||
let(:email) { |example| example.example_group.description } | ||
describe "no_at_symbol" do | ||
it { should have_errors_on_email.because("does not appear to be a valid e-mail address") } | ||
end | ||
describe "user1@gmail.com" do | ||
it { should_not have_errors_on_email } | ||
end | ||
end |
This file contains 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