rbehave 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rbehave.rb ADDED
@@ -0,0 +1,72 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'rbehave/**/*.rb')].sort.each { |lib| require lib }
2
+
3
+ module RBehave
4
+ def Story(title, narrative, &body)
5
+ RBehave::Runner::story_runner.Story(title, narrative, &body)
6
+ end
7
+
8
+ def self.included(into)
9
+ RBehave::Runner.register_instance
10
+ end
11
+
12
+ module Runner
13
+ class << self
14
+ def story_runner
15
+ unless @story_runner
16
+ scenario_runner = ScenarioRunner.new
17
+ world_creator = World
18
+ @story_runner = StoryRunner.new(scenario_runner, world_creator)
19
+ if ARGV.empty?
20
+ reporter = RBehave::Reporter::PlainTextReporter.new($stdout)
21
+ scenario_runner.add_listener(reporter)
22
+ @story_runner.add_listener(reporter)
23
+ else
24
+ documenter = RBehave::Documenter::PlainTextDocumenter.new($stdout)
25
+ scenario_runner.add_listener(documenter)
26
+ @story_runner.add_listener(documenter)
27
+ world_creator.add_listener(documenter)
28
+ self.dry_run = true
29
+ end
30
+ end
31
+ @story_runner
32
+ end
33
+
34
+ def register_instance
35
+ return if registered?
36
+ unless registered?
37
+ registered = true
38
+ Exception.add_backtrace_filter(/lib\/rbehave/)
39
+ Exception.add_backtrace_filter(/gems\/rspec/)
40
+ at_exit do
41
+ exit RBehave::Runner.run unless $! || RBehave::Runner.run?
42
+ end
43
+ end
44
+ end
45
+
46
+ def registered?
47
+ @registered ||= false
48
+ end
49
+
50
+ def run?
51
+ @run ||= false
52
+ end
53
+
54
+ def run=(value)
55
+ @run = value
56
+ end
57
+
58
+ def run
59
+ story_runner.run_stories
60
+ self.run = true
61
+ end
62
+
63
+ def dry_run?
64
+ @dry_run ||= false
65
+ end
66
+
67
+ def dry_run=(value)
68
+ @dry_run = value
69
+ end
70
+ end
71
+ end
72
+ end