Module: Coulda

Defined in:
lib/coulda.rb,
lib/coulda/world.rb

Defined Under Namespace

Classes: World

Constant Summary collapse

PROC_KEYWORDS =
[:Given, :When, :Then, :And]
KEYWORDS =
[:Scenario, :Tag, :in_order_to, :as_a, :i_want_to] + PROC_KEYWORDS
SyntaxError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_testcase_classObject



41
42
43
# File 'lib/coulda.rb', line 41

def self.default_testcase_class
  @class
end

.default_testcase_class=(klass) ⇒ Object



34
35
36
37
38
39
# File 'lib/coulda.rb', line 34

def self.default_testcase_class=(klass)
  unless klass.is_a?(Class) && klass.ancestors.include?(Test::Unit::TestCase)
    raise Exception, "Can only provide a Test::Unit::TestCase"
  end
  @class = klass
end

Instance Method Details

#Feature(name, opts = {}, &block) ⇒ Object

Factory method for Test::Unit::TestCase subclasses



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/coulda.rb', line 17

def Feature(name, opts = {}, &block)
  test_class = Class.new(opts[:testcase_class] || Coulda.default_testcase_class || Test::Unit::TestCase)

  assign_class_to_const test_class, name
  test_class.instance_eval do
    extend YourDSL
    record_your_dsl :only => Coulda::KEYWORDS, :retain_blocks_for => Coulda::PROC_KEYWORDS
  end
  test_class.instance_eval &block if block_given?

  World.register_feature(name, test_class.output)

  generate_test_methods_from test_class

  test_class
end