crb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +117 -0
  3. data/Rakefile +53 -0
  4. data/VERSION +1 -0
  5. data/bin/crb +6 -0
  6. data/crb.gemspec +57 -0
  7. data/lib/crb.rb +122 -0
  8. metadata +132 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [maiha@wota.jp]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,117 @@
1
+ crb
2
+ ===
3
+
4
+ An irb console for cucumber world
5
+
6
+
7
+ Features
8
+ ========
9
+
10
+ * Can define steps interactively
11
+ * Can execute steps interactively like debugger
12
+ * Can share cuke world and irb context in a same object
13
+ * Can see instance variables of step files via irb
14
+ * Supported hooks (but only before/after without parameters)
15
+
16
+
17
+ Usage
18
+ =====
19
+
20
+ Use 'crb' command as same as 'cucumber' command
21
+ % crb (... cucumber options ...)
22
+
23
+ And then you are in cucumber world via irb
24
+
25
+
26
+ Example
27
+ =======
28
+
29
+ % cd examples/i18n/en
30
+ % crb
31
+ irb(CRB:3):001:0>
32
+ ^^^ This means a number of defined steps.
33
+
34
+ irb(CRB:3):001:0> Given "I have entered 3"
35
+ Undefined step: "I have entered 3"
36
+ => #<Cucumber::Undefined: Undefined step: "I have entered 3">
37
+
38
+ irb(CRB:3):002:0> Given "I have entered 3 into the calculator"
39
+ => [3]
40
+
41
+ irb(CRB:3):003:0> Given "I have entered 5 into the calculator"
42
+ => [3, 5]
43
+
44
+ irb(CRB:3):004:0> Then "I press add"
45
+ => 8
46
+
47
+ irb(CRB:3):005:0> @calc
48
+ => #<Calculator:0x7faa0a3e5218 @args=[3, 5]>
49
+
50
+
51
+ I18N
52
+ ====
53
+
54
+ I18N keywords are also available.
55
+
56
+ % cd examples/i18n/ja
57
+ % crb
58
+ irb(CRB:3):001:0> 前提 "3 を入力"
59
+ => [3]
60
+ irb(CRB:3):002:0> @calc
61
+ => #<Calculator:0x7ff45ecdbc70 @args=[3]>
62
+
63
+
64
+ Custom
65
+ ======
66
+
67
+ % mkdir my-project
68
+ % crb my-project
69
+ irb(CRB:0):001:0> Given "ab"
70
+ Undefined step: "ab"
71
+ => #<Cucumber::Undefined: Undefined step: "ab">
72
+ irb(CRB:0):002:0> Given(/^(..)$/){|i| p "Two chars for you! #{i}"}
73
+ => "/^(..)$/ is defined"
74
+ irb(CRB:1):003:0> Given "ab"
75
+ "Two chars for you! ab"
76
+
77
+
78
+ World Methods
79
+ =============
80
+
81
+ Above crb(irb) context is a same object with cuke's world.
82
+ And there are following additional methods.
83
+
84
+ * before : execute before hooks. returns message (String)
85
+ * after : execute after hooks. returns message (String)
86
+ * steps : returns step definitions (Array[RbStepDefinition])
87
+ * runtime: returns runtime object (CRB::Runtime)
88
+ * hooks : returns hooks (Hash[type=>Array[RbHook]])
89
+ * rb : returns ruby language support object (RbLanguage)
90
+
91
+
92
+ Restricted
93
+ ==========
94
+
95
+ * Hooks are not called automatically because crb is free from
96
+ scenarios. Otherwise if hooks are called in each invokes,
97
+ we'll never succeed to "add" operation in above calculator.
98
+
99
+ * "before", "after" methods are the manual triggers for hooks.
100
+ And "Ctl-C" is binded as "before" filter too.
101
+
102
+ * To implement CRB, there are many ugly codes that closely
103
+ depend on cuke's internal structures like private methods
104
+ and instance vars. So it'll break soon after cuke's update.
105
+
106
+
107
+ Environment
108
+ ===========
109
+
110
+ Tested on ruby-1.8.7, cucumber-1.0.0
111
+
112
+
113
+ Author
114
+ ======
115
+
116
+ maiha@wota.jp
117
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "crb"
18
+ gem.homepage = "http://github.com/maiha/crb"
19
+ gem.license = "MIT"
20
+ gem.summary = "A cucumber console that offers cucumber world enviroment on irb"
21
+ gem.description = gem.summary
22
+ gem.email = "maiha@wota.jp"
23
+ gem.authors = ["maiha"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "crb #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/bin/crb ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # clear ARGV for Irb
3
+
4
+ require 'rubygems'
5
+ require 'crb'
6
+ CRB::Console.execute(ARGV.slice!(0..-1)||[])
data/crb.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{crb}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["maiha"]
12
+ s.date = %q{2011-07-10}
13
+ s.default_executable = %q{crb}
14
+ s.description = %q{TODO: longer description of your gem}
15
+ s.email = %q{maiha@wota.jp}
16
+ s.executables = ["crb"]
17
+ s.extra_rdoc_files = [
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/crb",
26
+ "crb.gemspec",
27
+ "lib/crb.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/maiha/crb}
30
+ s.licenses = ["MIT"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{TODO: one-line summary of your gem}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
41
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
42
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
43
+ s.add_development_dependency(%q<rcov>, [">= 0"])
44
+ else
45
+ s.add_dependency(%q<shoulda>, [">= 0"])
46
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
48
+ s.add_dependency(%q<rcov>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ end
56
+ end
57
+
data/lib/crb.rb ADDED
@@ -0,0 +1,122 @@
1
+ require 'cucumber'
2
+ require 'cucumber/formatter/unicode'
3
+ require 'cucumber/runtime'
4
+ require 'cucumber/rb_support/rb_dsl'
5
+ require 'irb'
6
+
7
+ module CRB
8
+ class Runtime < Cucumber::Runtime
9
+ def run!
10
+ load_step_definitions
11
+ fire_after_configuration_hook
12
+ end
13
+
14
+ def step_definitions
15
+ @support_code.step_definitions
16
+ end
17
+ end
18
+
19
+ module World
20
+ include Cucumber::RbSupport::RbDsl
21
+
22
+ attr_accessor :runtime
23
+ attr_accessor :rb
24
+
25
+ def to_s
26
+ "CRB:%s" % (steps.size rescue '???')
27
+ end
28
+
29
+ def steps
30
+ runtime.step_definitions
31
+ end
32
+
33
+ def hooks
34
+ rb.send(:hooks)
35
+ end
36
+
37
+ def before
38
+ fire_hook(:before)
39
+ end
40
+
41
+ def after
42
+ fire_hook(:after)
43
+ end
44
+
45
+ private
46
+ def Given(name, &block)
47
+ if block
48
+ step = super(name, &block)
49
+ "%s is defined" % (step.regexp_source rescue 'A new step')
50
+ else
51
+ @crb_before_executed ||= (before; true)
52
+ runtime.step_match(name).invoke(nil)
53
+ end
54
+ rescue Cucumber::Undefined => e
55
+ puts e.to_s
56
+ e
57
+ end
58
+
59
+ def fire_hook(key)
60
+ count = 0
61
+ hooks[key].each do |hook|
62
+ block = hook.instance_variable_get('@proc')
63
+ if block
64
+ instance_eval(&block)
65
+ count += 1
66
+ else
67
+ # cuke is newer than 1.0
68
+ end
69
+ end
70
+ "%d %s hooks executed" % [count, key]
71
+ end
72
+ end
73
+
74
+ class Console < Cucumber::Cli::Main
75
+ include IRB
76
+
77
+ def runtime
78
+ @runtime ||= CRB::Runtime.new(configuration)
79
+ end
80
+
81
+ def rb
82
+ @rb ||= runtime.load_programming_language('rb')
83
+ end
84
+
85
+ def world
86
+ @world ||= (
87
+ rb.send(:create_world)
88
+ world = rb.current_world
89
+ world.extend(CRB::World)
90
+ world.runtime = runtime
91
+ world.rb = rb
92
+ world.instance_eval do
93
+ Gherkin::I18n.code_keywords.each do |adverb|
94
+ next if adverb.to_s == "Given"
95
+ alias :"#{adverb}" :Given
96
+ end
97
+ end
98
+ world
99
+ )
100
+ end
101
+
102
+ def execute!
103
+ IRB.setup(__FILE__)
104
+ IRB.conf[:CONTEXT_MODE] = 0
105
+ irb = Irb.new(WorkSpace.new(world))
106
+ runtime.run!
107
+ IRB.module_eval do
108
+ @CONF[:MAIN_CONTEXT] = irb.context
109
+ end
110
+
111
+ trap("SIGINT") {
112
+ world.before
113
+ irb.signal_handle
114
+ }
115
+ catch(:IRB_EXIT) do
116
+ irb.eval_input
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - maiha
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-10 00:00:00 +09:00
19
+ default_executable: crb
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ prerelease: false
24
+ name: shoulda
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ prerelease: false
38
+ name: bundler
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ prerelease: false
54
+ name: jeweler
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 4
65
+ version: 1.6.4
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ prerelease: false
70
+ name: rcov
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirement: *id004
81
+ description: A cucumber console that offers cucumber world enviroment on irb
82
+ email: maiha@wota.jp
83
+ executables:
84
+ - crb
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - README
89
+ files:
90
+ - MIT-LICENSE
91
+ - README
92
+ - Rakefile
93
+ - VERSION
94
+ - bin/crb
95
+ - crb.gemspec
96
+ - lib/crb.rb
97
+ has_rdoc: true
98
+ homepage: http://github.com/maiha/crb
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project:
127
+ rubygems_version: 1.3.7
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: A cucumber console that offers cucumber world enviroment on irb
131
+ test_files: []
132
+