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

Commit

Permalink
Changed #it to #example (still aliased with #it and #specify). Also s…
Browse files Browse the repository at this point in the history
…ome refactoring in example_group_methods.
  • Loading branch information
dchelimsky committed Sep 30, 2008
1 parent 187ee1b commit f6b39b8
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions lib/spec/example/example_group_methods.rb
Expand Up @@ -38,24 +38,30 @@ def inherited(klass)
def describe(*args, &example_group_block)
args << {} unless Hash === args.last
if example_group_block
params = args.last
params[:spec_path] = eval("caller(0)[1]", example_group_block) unless params[:spec_path]
if params[:shared]
SharedExampleGroup.new(*args, &example_group_block)
options = args.last
options[:spec_path] = eval("caller(0)[1]", example_group_block) unless options[:spec_path]
if options[:shared]
create_shared_example_group(args, example_group_block)
else
self.subclass("Subclass") do
describe(*args)
module_eval(&example_group_block)
end
create_nested_example_group(args, example_group_block)
end
else
set_description(*args)
before_eval
self
end
end
alias :context :describe


def create_shared_example_group(args, example_group_block)
SharedExampleGroup.new(*args, &example_group_block)
end

def create_nested_example_group(args, example_group_block)
self.subclass("Subclass") do
describe(*args)
module_eval(&example_group_block)
end
end

# Use this to pull in examples from shared example groups.
# See Spec::Runner for information about shared example groups.
def it_should_behave_like(shared_example_group)
Expand Down Expand Up @@ -103,21 +109,24 @@ def predicate_matchers
@predicate_matchers ||= {:an_instance_of => :is_a?}
end

# Creates an instance of Spec::Example::Example and adds
# it to a collection of examples of the current example group.
def it(description=nil, &implementation)
# Creates an instance of the current example group class and adds it to
# a collection of examples of the current example group.
def example(description=nil, &implementation)
e = new(description, &implementation)
example_objects << e
e
end

alias_method :specify, :it
alias_method :it, :example
alias_method :specify, :example

# Use this to temporarily disable an example.
def xit(description=nil, opts={}, &block)
def xexample(description=nil, opts={}, &block)
Kernel.warn("Example disabled: #{description}")
end
alias_method :xspecify, :xit

alias_method :xit, :xexample
alias_method :xspecify, :xexample

def run
examples = examples_to_run
Expand Down Expand Up @@ -410,9 +419,6 @@ def after_parts_from_scope(scope)
end
end

def before_eval
end

def add_method_examples(examples)
instance_methods.sort.each do |method_name|
if example_method?(method_name)
Expand Down

0 comments on commit f6b39b8

Please sign in to comment.