Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Move registration of new exampel group to listener provided by Runner
Browse files Browse the repository at this point in the history
module (reducing dependency from Spec::Example to Spec::Runner).
  • Loading branch information
dchelimsky committed Dec 29, 2008
1 parent 3e33d3a commit 013fd6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
35 changes: 20 additions & 15 deletions lib/spec/example/example_group_methods.rb
Expand Up @@ -2,23 +2,23 @@ module Spec
module Example

module ExampleGroupMethods
include Spec::Example::BeforeAndAfterHooks

def self.matcher_class
@matcher_class
end

def self.matcher_class=(matcher_class)
@matcher_class = matcher_class
end
class << self
attr_accessor :matcher_class

def self.description_text(*args)
args.inject("") do |description, arg|
description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
description << arg.to_s
def description_text(*args)
args.inject("") do |description, arg|
description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
description << arg.to_s
end
end

def example_group_creation_listeners
@example_group_creation_listeners ||= []
end
end

include Spec::Example::BeforeAndAfterHooks

attr_reader :description_options, :spec_path
alias :options :description_options

Expand All @@ -42,8 +42,13 @@ def description_args

def inherited(klass)
super
Spec::Runner.options.add_example_group klass
Spec::Runner.register_at_exit_hook
register_example_group(klass)
end

def register_example_group(klass)
ExampleGroupMethods.example_group_creation_listeners.each do |l|
l.register_example_group(klass)
end
end

# Makes the describe/it syntax available from a class. For example:
Expand Down
10 changes: 10 additions & 0 deletions lib/spec/runner.rb
Expand Up @@ -10,6 +10,16 @@

module Spec
module Runner

class ExampleGroupCreationListener
def register_example_group(klass)
Spec::Runner.options.add_example_group klass
Spec::Runner.register_at_exit_hook
end
end

Spec::Example::ExampleGroupMethods.example_group_creation_listeners << ExampleGroupCreationListener.new

class << self
def configuration # :nodoc:
@configuration ||= Spec::Example::Configuration.new
Expand Down

0 comments on commit 013fd6a

Please sign in to comment.