Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Wrapped the matcher and macro up similar to how TB wrote Shoulda

  • Loading branch information...
commit 243075fc598e0e1c31df558efde89813688c5bd5 1 parent 3424ecf
@bcardarella bcardarella authored committed
Showing with 63 additions and 44 deletions.
  1. +0 −37 rspec_matchers/authlogic.rb
  2. +63 −7 shoulda_macros/authlogic.rb
View
37 rspec_matchers/authlogic.rb
@@ -1,37 +0,0 @@
-# Place this file into your spec/support/matchers directory
-#
-# Example:
-#
-# describe User do
-# it { should have_authlogic }
-# end
-
-module Authlogic
- module RspecMatchers
- def have_authlogic
- HaveAuthlogic.new
- end
-
- class HaveAuthlogic
-
- def matches?(subject)
- subject.respond_to?(:password=) && subject.respond_to?(:valid_password?)
- end
-
- def failure_message
- "Add the line 'acts_as_authentic' to your model"
- end
-
- def description
- "have Authlogic"
- end
- end
- end
-
-end
-
-if defined?(Spec)
- Spec::Runner.configure do |config|
- config.include(Authlogic::RspecMatchers)
- end
-end
View
70 shoulda_macros/authlogic.rb
@@ -1,13 +1,69 @@
+# Test::Unit
+# Place this file into your test/shoulda_macros directory
+#
+# Example:
+#
+# class UserTest
+# should_have_authlogic
+# end
+#
+# Rspec
+# Place this file into your spec/support/shoulda directory
+#
+# Example:
+#
+# describe User do
+# it { should have_authlogic }
+# end
+
module Authlogic
- module ShouldaMacros
- class Test::Unit::TestCase
- def self.should_be_authentic
+ module Shoulda
+
+ module Matchers
+ def have_authlogic
+ HaveAuthlogic.new
+ end
+ alias_method :be_authentic, :have_authlogic
+
+ class HaveAuthlogic
+
+ def matches?(subject)
+ subject.respond_to?(:password=) && subject.respond_to?(:valid_password?)
+ end
+
+ def failure_message
+ "Add the line 'acts_as_authentic' to your model"
+ end
+
+ def description
+ "have Authlogic"
+ end
+ end
+
+ end
+
+ module Macros
+ include Matchers
+
+ def should_have_authlogic
klass = described_type rescue model_class
- should "acts as authentic" do
- assert klass.new.respond_to?(:password=)
- assert klass.new.respond_to?(:valid_password?)
+ matcher = HaveAuthlogic.new
+
+ should matcher.description do
+ assert matcher.matches?(klass.new), matcher.failure_message
end
end
+ alias_method :should_be_authentic, :should_have_authlogic
+
end
+
+ end
+end
+
+if defined? Spec
+ Spec::Runner.configure do |config|
+ config.include(Authlogic::Shoulda::Matchers)
end
-end
+else
+ Test::Unit::TestCase.class_eval { extend Authlogic::Shoulda::Macros }
+end
Please sign in to comment.
Something went wrong with that request. Please try again.