Class: Coulda::Feature
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Coulda::Feature
- Defined in:
- lib/coulda/feature.rb
Class Method Summary collapse
- .as_a(who) ⇒ Object
- .assert_description ⇒ Object
- .for_name(name) ⇒ Object
- .i_want_to(what) ⇒ Object
- .in_order_to(what) ⇒ Object
- .pending? ⇒ Boolean
- .Scenario(name, &test_implementation) ⇒ Object
- .scenarios ⇒ Object
Instance Method Summary collapse
-
#default_test ⇒ Object
Scenario-less features should be pending.
Class Method Details
.as_a(who) ⇒ Object
8 9 10 |
# File 'lib/coulda/feature.rb', line 8 def as_a(who) @as_a = who end |
.assert_description ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/coulda/feature.rb', line 23 def assert_description if @in_order_to || @as_a || @i_want_to raise SyntaxError.new("Must call in_order_to if as_a and/or i_wanted_to called") unless @in_order_to raise SyntaxError.new("Must call as_a if in_order_to and/or i_want_to called") unless @as_a raise SyntaxError.new("Must call i_want_to if in_order_to and/or as_a called") unless @i_want_to end end |
.for_name(name) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/coulda/feature.rb', line 16 def for_name(name) klass = Class.new(Feature) class_name = "Feature" + name.split(/\s/).map { |w| w.capitalize }.join Object.const_set(class_name, klass) klass end |
.i_want_to(what) ⇒ Object
12 13 14 |
# File 'lib/coulda/feature.rb', line 12 def i_want_to(what) @i_want_to = what end |
.in_order_to(what) ⇒ Object
4 5 6 |
# File 'lib/coulda/feature.rb', line 4 def in_order_to(what) @in_order_to = what end |
.pending? ⇒ Boolean
48 49 50 |
# File 'lib/coulda/feature.rb', line 48 def pending? @scenarios.all? { |s| !s.pending? } end |
.Scenario(name, &test_implementation) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/coulda/feature.rb', line 31 def Scenario(name, &test_implementation) raise SyntaxError.new("A scenario requires a name") unless name method_name = "test_#{name.sub(/\s/, "_").downcase}" @scenarios ||= [] @scenarios << scenario = Scenario.new(name, &test_implementation) if scenario.pending? define_method(method_name) { pending } else define_method(method_name, &test_implementation) end scenario end |
.scenarios ⇒ Object
44 45 46 |
# File 'lib/coulda/feature.rb', line 44 def scenarios @scenarios ||= [] end |
Instance Method Details
#default_test ⇒ Object
Scenario-less features should be pending
54 55 56 |
# File 'lib/coulda/feature.rb', line 54 def default_test pending end |