Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RSpec matchers

  • Loading branch information...
commit d3a4acbc96bb7f531959a9125fa9ec465db5444b 1 parent 7461f5a
@kalys kalys authored
View
8 lib/simple-private-messages/matchers.rb
@@ -0,0 +1,8 @@
+require 'simple-private-messages/matchers/have_private_messages_matcher'
+
+module SimplePrivateMessages
+ module Shoulda
+ module Matchers
+ end
+ end
+end
View
1  lib/simple-private-messages/matchers/have_private_messages_matcher
@@ -0,0 +1 @@
+module SimplePrivateMessages
View
69 lib/simple-private-messages/matchers/have_private_messages_matcher.rb
@@ -0,0 +1,69 @@
+module Professionalnerd # :nodoc:
+ module SimplePrivateMessages # :nodoc:
+ module Shoulda # :nodoc:
+ module Matchers # :nodoc:
+
+ def be_private_message
+ BePrivateMessage.new
+ end
+
+ class BePrivateMessage
+ def matches? subject
+ @subject = subject
+ @subject = @subject.class unless Class === @subject
+ included?
+ end
+
+ def failure_message
+ "Should be private message"
+ end
+
+ def negative_failure_message
+ "Should not be private message"
+ end
+
+ def description
+ "is private message"
+ end
+
+ protected
+
+ def included?
+ @subject.ancestors.include?(Professionalnerd::SimplePrivateMessages::PrivateMessageExtensions::InstanceMethods)
+ end
+ end
+
+ def have_private_messages
+ HavePrivateMessagesMatcher.new
+ end
+
+ class HavePrivateMessagesMatcher # :nodoc:
+
+ def matches? subject
+ @subject = subject
+ @subject = @subject.class unless Class === @subject
+ included?
+ end
+
+ def failure_message
+ "Should have 'has_private_messages' method"
+ end
+
+ def negative_failure_message
+ "Should not have 'has_private_messages' method"
+ end
+
+ def description
+ "have private messages"
+ end
+
+ protected
+
+ def included?
+ @subject.ancestors.include?(Professionalnerd::SimplePrivateMessages::HasPrivateMessagesExtensions::InstanceMethods)
+ end
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.