maiha-crb 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/crb.rb +75 -33
- metadata +1 -1
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "maiha"
|
|
9
9
|
EMAIL = "maiha@wota.jp"
|
10
10
|
HOMEPAGE = "http://github.com/maiha/crb"
|
11
11
|
SUMMARY = "A cucumber console that offers cucumber world enviroment on irb"
|
12
|
-
GEM_VERSION = "0.1.
|
12
|
+
GEM_VERSION = "0.1.2"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.rubyforge_project = 'asakusarb'
|
data/lib/crb.rb
CHANGED
@@ -5,19 +5,34 @@ require 'irb'
|
|
5
5
|
|
6
6
|
class CRB < Cucumber::Cli::Main
|
7
7
|
extend IRB
|
8
|
-
|
8
|
+
end
|
9
|
+
CRB.step_mother = self
|
9
10
|
|
11
|
+
class CRB
|
10
12
|
class << self
|
13
|
+
attr_accessor :irb
|
14
|
+
|
11
15
|
def world
|
12
|
-
|
16
|
+
unless @world
|
17
|
+
@world = CRB.step_mother
|
18
|
+
def @world.to_s
|
19
|
+
"World"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@world
|
13
23
|
end
|
14
24
|
|
15
25
|
def start(args)
|
16
26
|
IRB.setup(__FILE__)
|
17
|
-
|
18
|
-
|
27
|
+
IRB.conf[:CONTEXT_MODE] = 0
|
28
|
+
ws = WorkSpace.new(world)
|
29
|
+
CRB.irb = Irb.new(ws)
|
19
30
|
IRB.module_eval do
|
20
|
-
@CONF[:MAIN_CONTEXT] = irb.context
|
31
|
+
@CONF[:MAIN_CONTEXT] = CRB.irb.context
|
32
|
+
end
|
33
|
+
|
34
|
+
step_mother.World do
|
35
|
+
world
|
21
36
|
end
|
22
37
|
|
23
38
|
execute(args)
|
@@ -29,46 +44,61 @@ class CRB < Cucumber::Cli::Main
|
|
29
44
|
trap("SIGINT") do
|
30
45
|
irb.signal_handle
|
31
46
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
47
|
+
|
48
|
+
around_hooks do
|
49
|
+
catch(:IRB_EXIT) do
|
50
|
+
irb.eval_input
|
51
|
+
end
|
35
52
|
end
|
36
53
|
end
|
37
54
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
55
|
+
def around_hooks(&block)
|
56
|
+
step_mother.hooks[:before].each do |hook|
|
57
|
+
hook.execute(world)
|
58
|
+
end
|
41
59
|
|
42
|
-
|
43
|
-
extend ::Webrat::Matchers
|
60
|
+
block.call
|
44
61
|
|
45
|
-
|
46
|
-
|
47
|
-
if Webrat.configure.mode == :mechanize
|
48
|
-
webrat_session.mechanize.user_agent_alias = 'Windows Mozilla'
|
49
|
-
end
|
62
|
+
step_mother.hooks[:after].each do |hook|
|
63
|
+
hook.execute(world)
|
50
64
|
end
|
65
|
+
end
|
51
66
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
EOF
|
67
|
+
def alias_adverbs
|
68
|
+
world.instance_eval do
|
69
|
+
hash = Cucumber.keyword_hash
|
70
|
+
keywords = %w{given when then and but}.map{|keyword| hash[keyword].split('|')}.flatten
|
71
|
+
keywords.each do |name|
|
72
|
+
instance_eval "alias :'#{name}' :__cucumber_invoke"
|
59
73
|
end
|
60
74
|
end
|
61
75
|
end
|
62
76
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
77
|
+
def enable_session(mode = nil)
|
78
|
+
require 'webrat'
|
79
|
+
require 'webrat/core/matchers'
|
80
|
+
|
81
|
+
world.instance_eval do
|
82
|
+
extend ::Webrat::Methods
|
83
|
+
extend ::Webrat::Matchers
|
84
|
+
|
85
|
+
if mode || !Webrat.configure.mode
|
86
|
+
Webrat.configure.mode = (mode || :mechanize)
|
87
|
+
if Webrat.configure.mode == :mechanize
|
88
|
+
webrat_session.mechanize.user_agent_alias = 'Windows Mozilla'
|
70
89
|
end
|
71
|
-
|
90
|
+
end
|
91
|
+
|
92
|
+
%w{response post}.each do |m|
|
93
|
+
unless respond_to?(m, true)
|
94
|
+
instance_eval <<-EOF
|
95
|
+
def #{m}(*args, &blk)
|
96
|
+
webrat.#{m}(*args, &blk)
|
97
|
+
end
|
98
|
+
EOF
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
72
102
|
end
|
73
103
|
end
|
74
104
|
end
|
@@ -85,6 +115,18 @@ class CRB < Cucumber::Cli::Main
|
|
85
115
|
visitor = configuration.build_formatter_broadcaster(step_mother)
|
86
116
|
step_mother.visitor = visitor # Needed to support World#announce
|
87
117
|
end
|
118
|
+
|
119
|
+
module ExecuteProc
|
120
|
+
def execute(world)
|
121
|
+
world.instance_eval(&@proc)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
88
125
|
end
|
89
126
|
|
90
127
|
CRB.step_mother = self
|
128
|
+
|
129
|
+
Cucumber::StepMother::Hook.class_eval do
|
130
|
+
include CRB::ExecuteProc
|
131
|
+
end
|
132
|
+
|