Skip to content

Commit

Permalink
Added should observe. Patch by Luke Melia.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshknowles committed Mar 3, 2008
1 parent ce4a82a commit 4e88e05
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -4,5 +4,6 @@ Change Log
Trunk
-----

* 2008/03/02 - Added should observe (Luke Melia)
* 2008/03/02 - Patched validates_length_of to use within to be consistent with Rails (Matt Pelletier)
* 2007/01/03 - Initial Public Release
9 changes: 8 additions & 1 deletion README
Expand Up @@ -51,6 +51,11 @@ Adds the following RSpec matchers:
object.should validate_length_of(:attribute, :is => 5)
TM snippet: [msvl + tab]

* Observers:
Verify that the observer is observing a class. (doesn't verify that the observation works)

object.should observe(:model)
example: GroupObserver.should observe(Group)

* Views:
Verifies that the views contains some tags.
Expand Down Expand Up @@ -173,6 +178,8 @@ Core Contributors
Contributors
-------------

* ckknight (improved should validate_length_of)
* ckknight
* Matt Pelletier
* Luke Melia

Copyright (c) 2008 The Plugin Development Team, released under the MIT license
4 changes: 3 additions & 1 deletion init.rb
@@ -1,3 +1,5 @@
require 'spec/rails/matchers/observers'
require 'spec/rails/matchers/associations'
require 'spec/rails/matchers/validations'
require 'spec/rails/matchers/views'
require 'spec/rails/matchers/views'
require 'spec/rails/matchers/observers'
34 changes: 34 additions & 0 deletions lib/spec/rails/matchers/observers.rb
@@ -0,0 +1,34 @@
module Spec
module Rails
module Matchers

class Observe
def initialize(expected_model_class)
@expected_model_class = expected_model_class
end

def matches?(observer)
@observer = observer
if @observer.is_a?(ActiveRecord::Observer)
@observer = @observer.class
end
@observed_classes = observer.observed_classes.flatten
@observed_classes.include?(@expected_model_class)
end

def failure_message
return "expected #{@observer.name} to observe #{@expected_model_class.name}, but it was not included in [#{@observed_classes.map(&:name).join(', ')}]"
end

def description
"observer to be observing #{@expected_model_class.name}"
end
end

def observe(expected_model_class)
Observe.new(expected_model_class)
end

end
end
end

0 comments on commit 4e88e05

Please sign in to comment.