Skip to content

Commit

Permalink
Updated specs to use new RSpec syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Dayton committed Jun 19, 2014
1 parent d536f2a commit 5027165
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
7 changes: 5 additions & 2 deletions spec/dns_check_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
require 'spec_helper'

# I hope no one registers this
NOT_A_REAL_DOMAIN = "zjnajkndsjkangunausgnasngiuansiugnaiusngansjkgnaskjnaksjdn.com"

module DomainValidator
describe DnsCheck do
describe '#has_record?' do

context "given a domain without a DNS record" do
it "should return false" do
DnsCheck.has_record?("a.com").should be_false
expect( DnsCheck.has_record?(NOT_A_REAL_DOMAIN) ).to eq false
end
end

context "given a domain with a DNS record" do
it "should return true" do
DnsCheck.has_record?("example.com").should be_true
expect( DnsCheck.has_record?("example.com") ).to eq true
end
end

Expand Down
58 changes: 38 additions & 20 deletions spec/domain_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,56 @@
describe DomainValidator do
context "with valid domain" do
valid_domains.each do |domain|
user = User.new(:domain => domain)

it "#{domain} should be valid" do
User.new(:domain => domain).should be_valid
expect(user).to be_valid
end
end
end

context "with invalid domain" do
invalid_domains.each do |domain|
user = User.new(:domain => domain)

it "#{domain} should be invalid" do
User.new(:domain => domain).should_not be_valid
expect(user).to_not be_valid
end
end
end

describe "nil domain" do

it "should not be valid when :allow_nil option is missing" do
User.new(:domain => nil).should_not be_valid
user = User.new(:domain => nil)
expect(user).to_not be_valid
end

it "should be valid when :allow_nil option is true" do
UserAllowsNil.new(:domain => nil).should be_valid
user = UserAllowsNil.new(:domain => nil)
expect(user).to be_valid
end

it "should not be valid when :allow_nil option is false" do
UserAllowsNilFalse.new(:domain => nil).should_not be_valid
user = UserAllowsNilFalse.new(:domain => nil)
expect(user).to_not be_valid
end
end

describe "blank domain" do
it "should not be valid when :allow_blank option is missing" do
User.new(:domain => " ").should_not be_valid
user = User.new(:domain => " ")
expect(user).to_not be_valid
end

it "should be valid when :allow_blank option is true" do
UserAllowsBlank.new(:domain => " ").should be_valid
user = UserAllowsBlank.new(:domain => " ")
expect(user).to be_valid
end

it "should not be valid when :allow_blank option is false" do
UserAllowsBlankFalse.new(:domain => " ").should_not be_valid
user = UserAllowsBlankFalse.new(:domain => " ")
expect(user).to_not be_valid
end
end

Expand All @@ -52,7 +63,7 @@
before { subject.valid? }

it "should add the default message" do
subject.errors[:domain].should include "is invalid"
expect(subject.errors[:domain]).to include "is invalid"
end
end

Expand All @@ -61,7 +72,7 @@
before { subject.valid? }

it "should add the customized message" do
subject.errors[:domain].should include "isn't quite right"
expect(subject.errors[:domain]).to include "isn't quite right"
end
end

Expand All @@ -70,7 +81,7 @@
before { subject.valid? }

it "should add the customized message" do
subject.errors[:domain].should include "failed DNS check"
expect(subject.errors[:domain]).to include "failed DNS check"
end
end

Expand All @@ -79,44 +90,51 @@
before { subject.valid? }

it "should add the default message" do
subject.errors[:domain].should include "does not have a DNS record"
expect(subject.errors[:domain]).to include "does not have a DNS record"
end
end
end

describe "DNS check" do
describe "an invalid domain" do
it "should not perform a DNS check" do
DomainValidator::DnsCheck.any_instance.should_not_receive(:has_record?)
UserVerifyDNS.new(:domain => "notadomain").should_not be_valid
expect_any_instance_of(DomainValidator::DnsCheck).to_not receive(:has_record?)
user = UserVerifyDNS.new(:domain => "notadomain")
expect(user).to_not be_valid
end
end

describe "a domain with a DNS record" do
it "should be valid when :verify_dns is true" do
UserVerifyDNS.new(:domain => "example.com").should be_valid
user = UserVerifyDNS.new(:domain => "example.com")
expect(user).to be_valid
end

it "should be valid when :verify_dns is false" do
UserVerifyDNSFalse.new(:domain => "example.com").should be_valid
user = UserVerifyDNSFalse.new(:domain => "example.com")
expect(user).to be_valid
end

it "should be valid when :verify_dns is undefined" do
User.new(:domain => "example.com").should be_valid
user = User.new(:domain => "example.com")
expect(user).to be_valid
end
end

describe "a domain without a DNS record" do
it "should not be valid when :verify_dns is true" do
UserVerifyDNS.new(:domain => "a.com").should_not be_valid
user = UserVerifyDNS.new(:domain => "a.com")
expect(user).to_not be_valid
end

it "should be valid when :verify_dns is false" do
UserVerifyDNSFalse.new(:domain => "a.com").should be_valid
user = UserVerifyDNSFalse.new(:domain => "a.com")
expect(user).to be_valid
end

it "should be valid when :verify_dns is undefined" do
User.new(:domain => "a.com").should be_valid
user = User.new(:domain => "a.com")
expect(user).to be_valid
end
end
end
Expand Down

0 comments on commit 5027165

Please sign in to comment.