maiha-crb 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/crb.rb +75 -33
  3. 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.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
- extend Cucumber::World
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
- step_mother.current_world
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
- ws = WorkSpace.new(binding)
18
- irb = Irb.new(ws)
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
- catch(:IRB_EXIT) do
34
- irb.eval_input
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 enable_session(mode = nil)
39
- require 'webrat'
40
- require 'webrat/core/matchers'
55
+ def around_hooks(&block)
56
+ step_mother.hooks[:before].each do |hook|
57
+ hook.execute(world)
58
+ end
41
59
 
42
- extend ::Webrat::Methods
43
- extend ::Webrat::Matchers
60
+ block.call
44
61
 
45
- if mode || !Webrat.configure.mode
46
- Webrat.configure.mode = (mode || :mechanize)
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
- %w{response post}.each do |m|
53
- unless respond_to?(m, true)
54
- instance_eval <<-EOF
55
- def self.#{m}(*args, &blk)
56
- webrat.#{m}(*args, &blk)
57
- end
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 alias_adverbs
64
- hash = Cucumber.keyword_hash
65
- keywords = %w{given when then and but}.map{|keyword| hash[keyword].split('|')}.flatten
66
- keywords.each do |name|
67
- instance_eval <<-EOF
68
- def CRB.#{name}(*args, &blk)
69
- world.#{name}(*args, &blk)
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
- EOF
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
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maiha-crb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - maiha