forked from joshknowles/rspec-on-rails-matchers
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added should observe. Patch by Luke Melia.
- Loading branch information
1 parent
ce4a82a
commit 4e88e05
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |