Skip to content

Commit

Permalink
Encapsulated some of the anonymous Module / Class construction logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Lauber committed Dec 9, 2012
1 parent eba3bad commit d0ef6bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
23 changes: 23 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,26 @@

end


module Unobservable
module SpecHelper

def module_with_instance_events(*names)
Module.new do
include Unobservable::Support
attr_event *names
end
end

def class_with_instance_events(*names)
args = {superclass: Object}
args.merge!(names.pop) if names[-1].is_a? Hash

Class.new(args[:superclass]) do
include Unobservable::Support
attr_event *names
end
end

end
end
33 changes: 4 additions & 29 deletions spec/unobservable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,7 @@


describe Unobservable do

def module_with_instance_events(*names)
Module.new do
include Unobservable::Support
attr_event *names
end
end

def class_with_instance_events(*names)
Class.new do
include Unobservable::Support
attr_event *names
end
end

include Unobservable::SpecHelper

describe "#instance_events_for" do

Expand All @@ -96,10 +82,7 @@ def class_with_instance_events(*names)

describe "#collect_instance_events_defined_by" do
let(:mixin_module) do
Module.new do
include Unobservable::Support
attr_event :mixin_1, :mixin_2
end
module_with_instance_events(:mixin_1, :mixin_2)
end

let(:module_that_includes_mixin) do
Expand All @@ -113,19 +96,11 @@ def class_with_instance_events(*names)
end

let(:baseclass) do
Class.new do
include Unobservable::Support
attr_event :bc_1, :bc_2
end
class_with_instance_events(:bc_1, :bc_2)
end

let(:subclass) do
m = module_that_includes_mixin

Class.new(baseclass) do
include m
attr_event :sc_1, :sc_2
end
class_with_instance_events(:sc_1, :sc_2, superclass: baseclass)
end


Expand Down

0 comments on commit d0ef6bf

Please sign in to comment.