-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some more tests around the abstract base rule
- Loading branch information
Showing
5 changed files
with
72 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
shared_context 'rule class helpers' do | ||
def new_rule_class(name) | ||
scope = Module.new | ||
scope.module_eval <<-end_module, __FILE__, __LINE__ | ||
class #{name} < #{described_class}; end | ||
end_module | ||
|
||
scope.const_get(name) | ||
end | ||
|
||
end |
27 changes: 27 additions & 0 deletions
27
spec/unit/dotum/abstract_rules/base/class_methods/exec_spec.rb
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,27 @@ | ||
describe Dotum::AbstractRules::Base, '.exec' do | ||
include_context 'rule class helpers' | ||
|
||
subject do | ||
new_rule_class(:SomeRuleClass).tap do |klass| | ||
klass.class_eval do | ||
def initialize(context, *args, &block) | ||
@context = context | ||
@args = args | ||
@block = block | ||
end | ||
|
||
def exec | ||
[@context, @args, @block] | ||
end | ||
end | ||
end | ||
end | ||
|
||
it 'should pass through all arguments to initialize' do | ||
context = Dotum::Context.new | ||
expect(subject.exec(context, 1, 2, &:asdf)).to eq([ | ||
context, [1, 2], :asdf.to_proc | ||
]) | ||
end | ||
|
||
end |
20 changes: 6 additions & 14 deletions
20
spec/unit/dotum/abstract_rules/base/class_methods/pretty_spec.rb
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
describe Dotum::AbstractRules::Base, '#execute' do | ||
include_context 'rule class helpers' | ||
|
||
subject do | ||
new_rule_class(:SomeRule).new(Dotum::Context.new) | ||
end | ||
|
||
it 'should be abstract' do | ||
expect { subject.exec }.to raise_error( | ||
NotImplementedError, /execute/ | ||
) | ||
end | ||
|
||
end |
14 changes: 14 additions & 0 deletions
14
spec/unit/dotum/abstract_rules/base/pretty_subject_spec.rb
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,14 @@ | ||
describe Dotum::AbstractRules::Base, '#pretty_subject' do | ||
include_context 'rule class helpers' | ||
|
||
subject do | ||
new_rule_class(:SomeRule).new(Dotum::Context.new) | ||
end | ||
|
||
it 'should be abstract' do | ||
expect { subject.pretty_subject }.to raise_error( | ||
NotImplementedError, /pretty_subject/ | ||
) | ||
end | ||
|
||
end |