Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Add tests to demonstrate nil error in content type matcher failure me…
Browse files Browse the repository at this point in the history
…ssage

Note: this is most likely not the way we want to test our matchers, but it
demonstrates the current issue.
  • Loading branch information
lime committed Feb 15, 2016
1 parent 37589f9 commit 719d293
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,58 @@

it "rejects a class with no validation" do
expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it 'rejects a class when the validation fails' do
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "accepts a class with a matching validation" do
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "accepts a class with other validations but matching types" do
Dummy.validates_presence_of :title
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "accepts a class that matches and a matcher that only specifies 'allowing'" do
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
matcher = plain_matcher.allowing(%w(image/png image/jpeg))

expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "rejects a class that does not match and a matcher that only specifies 'allowing'" do
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
matcher = plain_matcher.allowing(%w(image/png image/jpeg))

expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "accepts a class that matches and a matcher that only specifies 'rejecting'" do
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))

expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "rejects a class that does not match and a matcher that only specifies 'rejecting'" do
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))

expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end

context "using an :if to control the validation" do
Expand All @@ -75,12 +83,14 @@
dummy = Dummy.new
dummy.go = true
expect(matcher).to accept(dummy)
expect { matcher.failure_message }.to_not raise_error
end

it "does not run the validation if the control is false" do
dummy = Dummy.new
dummy.go = false
expect(matcher).to_not accept(dummy)
expect { matcher.failure_message }.to_not raise_error
end
end

Expand Down

0 comments on commit 719d293

Please sign in to comment.