Module: TestMe
- Defined in:
- lib/testme.rb,
lib/logic.rb,
lib/double.rb,
lib/formatter.rb
Overview
********************************************************************#
-
*#
-
Test Me *#
-
*#
********************************************************************#
Defined Under Namespace
Modules: Formatter Classes: Context, Double
Constant Summary collapse
- @@failed =
false- @@config =
Configatron::Store.new
Class Method Summary collapse
Instance Method Summary collapse
-
#also(*args, &block) ⇒ Object
Provide a context over the existing context ‘ given name: ’Flavie’ ‘ ` also class: ’Rogue’ ‘.
-
#before(&block) ⇒ Object
Create a base context Re-runs every time ‘given’ is called ‘ before do <block> end `.
-
#given(*args, &block) ⇒ Object
Provide a context stubbing an attribute ‘ given name: ’Flavie’, class: ‘Rogue’ ‘ ` given { topic.name = ’Flavie; topic.class = ‘Rogue’ } ‘ calling a method ` given { topic.talk_to ’Deckard’ } ‘.
-
#is?(*args, &block) ⇒ Boolean
Create an assertion ‘ is? name: ’Flavie’ ‘ ` is? :inventory, ’Arrows’ ‘ ` is? { topic.inventory(1) == ’Arrows’ } ‘.
-
#test(topic, *args) ⇒ Object
Set the topic of the test ‘ test Player `.
-
#topic ⇒ Object
Retrieve the topic of the test.
Class Method Details
.config ⇒ Object
68 |
# File 'lib/testme.rb', line 68 def self.config; @@config; end |
.failed? ⇒ Boolean
104 105 106 |
# File 'lib/logic.rb', line 104 def self.failed? @@failed end |
.formatter ⇒ Object
100 101 102 |
# File 'lib/logic.rb', line 100 def self.formatter @@formatter end |
Instance Method Details
#also(*args, &block) ⇒ Object
Provide a context over the existing context
` given name: 'Flavie' `
` also class: 'Rogue' `
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/testme.rb', line 37 def also desc=nil, stubs=nil, &block @@formatter.also desc, stubs, &block if desc.class == String || desc.class == Symbol if stubs == nil and block == nil load_context desc return end save_context desc, stubs, &block elsif desc.class.name == 'Hash' stubs = desc end set_context stubs, &block end |
#before(&block) ⇒ Object
Create a base context Re-runs every time ‘given’ is called
` before do <block> end `
50 51 52 |
# File 'lib/testme.rb', line 50 def before &block @before = block end |
#given(*args, &block) ⇒ Object
Provide a context
stubbing an attribute
` given name: 'Flavie', class: 'Rogue' `
` given { topic.name = 'Flavie; topic.class = 'Rogue' } `
calling a method
` given { topic.talk_to 'Deckard' } `
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/testme.rb', line 31 def given desc=nil, stubs=nil, &block @before.call if @before @@formatter.given desc, stubs, &block reset_topic if desc.class == String || desc.class == Symbol if stubs == nil and block == nil load_context desc return end save_context desc, stubs, &block elsif desc.class == Hash stubs = desc end set_context stubs, &block end |
#is?(*args, &block) ⇒ Boolean
Create an assertion
` is? name: 'Flavie' `
` is? :inventory[1], 'Arrows' `
` is? { topic.inventory(1) == 'Arrows' } `
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/testme.rb', line 44 def is? *args, &block if block method = block result = block.call else if args[0].is_a? Hash method = args[0].first[0] expected = args[0].first[1] actual = topic.send(method) end if args[0].is_a? Symbol params = args[0].args expected = args[1] actual = topic.send(args[0], *params) method = args[0].to_s + ( params.size > 0 ? '(' + params.join(',') + ')' : '') end expected = true if expected.nil? result = actual == expected end @@formatter.is? method, actual, expected, result @@failed = true if result == false result end |
#test(topic, *args) ⇒ Object
Set the topic of the test
` test Player `
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/testme.rb', line 22 def test topic, *args @topic = nil @before = nil @contexts = {} @args = args @@formatter = Formatter::create(testme.format) case topic.class when String || Symbol @topic_class = Object @@formatter.test topic else @topic_class = topic @@formatter.test @topic_class end reset_topic end |
#topic ⇒ Object
Retrieve the topic of the test
17 18 19 |
# File 'lib/testme.rb', line 17 def topic @topic end |