cucumberator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- Cucumberator is Cucumber extension to write steps in command line while whatching how browser responds to them:
1
+ Cucumberator is Cucumber extension to write steps in command line, whatch how browser responds to them and save directly to your .feature file.
2
2
 
3
- ## Usage
3
+ ## How to use
4
4
 
5
5
  * Put @cucumberize tag in front of Scenario you want to append with new steps
6
6
  * Fire up the cucumber and wait until prompt shows up
@@ -8,7 +8,11 @@ Cucumberator is Cucumber extension to write steps in command line while whatchin
8
8
 
9
9
  ## Installation
10
10
 
11
- If you use bundler (and you should), add 'cucumberator' to your Gemfile. Otherwise, install with
11
+ If you use bundler (and you should), add to your Gemfile
12
+
13
+ gem "cucumberator", :require => false
14
+
15
+ Otherwise, install with
12
16
 
13
17
  gem install cucumberator
14
18
 
@@ -19,11 +23,17 @@ Then require it in one of your ruby files under features/support (e.g. env.rb)
19
23
  Now put @cucumberize before any Scenario you want to fill up, for example
20
24
 
21
25
  @javascript @cucumberize
22
- Scenario: check fancy ajax login
23
- Given user with email some@example.com
26
+ Scenario: check fancy ajax login
27
+ Given user with email some@example.com
28
+
29
+ and then run this feature file and watch your console for prompt shows up - after all existing steps are finished.
30
+
31
+ ## TODO
24
32
 
25
- and then run this feature file and watch your console for prompt shows up.
33
+ * support of multiple scenarios per feature file
34
+ * autocomplete for available steps
35
+ * tests
26
36
 
27
- ## What cucumberator DOES NOT DO
37
+ ## SUGGESTIONS?
28
38
 
29
- It doesn't let you define your new step defitions yet.
39
+ Drop me a line or feel free to contribute!
data/cucumberator.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "https://github.com/vidmantas/cucumberator"
11
11
  s.summary = "cucumberator-#{s.version}"
12
12
  s.description = %q{Prompt for writing Cucumber tests}
13
- s.post_install_message = "(::)\nCucumberator installed! Now require cucumberator/cucumberize in your env.rb and place @cucumberize before the scenario you'd like to append new steps\n(::)"
13
+ s.post_install_message = "(::)\nCucumberator installed! Now require cucumberator in your env.rb and place @cucumberize before the scenario you'd like to append new steps\n(::)"
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/cucumberator.rb CHANGED
@@ -1,2 +1,6 @@
1
- require "cucumberator/version"
2
- require "cucumberator/cucumberize"
1
+ require "readline"
2
+ require "cucumberator/cucumberizator"
3
+
4
+ After('@cucumberize') do |scenario|
5
+ Cucumberizator.new(self, scenario)
6
+ end
@@ -0,0 +1,105 @@
1
+ class Cucumberizator
2
+ attr_accessor :world, :scenario, :last_input, :exit_flag
3
+
4
+ FULL_BACKTRACE = false
5
+
6
+ def initialize(world, scenario)
7
+ @world, @scenario = world, scenario
8
+
9
+ check_scenario
10
+ set_autocomplete
11
+ read_input
12
+ end
13
+
14
+ def check_scenario
15
+ raise "Sorry, no cucumberator when scenario is already failing!" if scenario.failed?
16
+ end
17
+
18
+ def set_autocomplete
19
+ commands = %w(exit exit-all help last-step save)
20
+ Readline.completion_proc = proc{|s| commands.grep( /^#{Regexp.escape(s)}/ ) }
21
+ end
22
+
23
+ def read_input
24
+ input = Readline.readline("> ", true)
25
+ parse_input(input)
26
+ read_input unless exit_flag
27
+ end
28
+
29
+ def parse_input(input)
30
+ case input
31
+ when "exit"
32
+ self.exit_flag = true and return
33
+
34
+ when "exit-all"
35
+ Cucumber.wants_to_quit = true
36
+ self.exit_flag = true and return
37
+
38
+ when "help"
39
+ display_help
40
+
41
+ when "last-step"
42
+ puts last_input
43
+
44
+ when "save"
45
+ save_last_input
46
+
47
+ else
48
+ execute_cucumber_step(input)
49
+
50
+ end
51
+ rescue Exception => e
52
+ puts e.inspect
53
+ puts e.backtrace.join("\n") if FULL_BACKTRACE
54
+ end
55
+
56
+
57
+ ## COMMANDS
58
+
59
+ def display_help
60
+ puts ":: Write a step here and watch it happen on the browser"
61
+ puts ":: Available commands:"
62
+ puts ":: save - saves last step into current feature file"
63
+ puts ":: last-step - display last executed step (to be saved on 'save' command)"
64
+ puts ":: exit - exits current scenario"
65
+ puts ":: exit-all - exists whole Cucumber feature"
66
+ puts ":: help - display this notification"
67
+ end
68
+
69
+ def save_last_input
70
+ if last_input.blank?
71
+ puts "Hm... nothing to save yet?"
72
+ else
73
+ File.open(feature_file, 'a') do |f|
74
+ f.puts((" " * spaces_in_last_line) + last_input)
75
+ end
76
+
77
+ puts "Saved \"#{last_input}\" to #{File.basename(feature_file)}"
78
+ self.last_input = nil
79
+ end
80
+ end
81
+
82
+ def execute_cucumber_step(input)
83
+ self.last_input = input
84
+ input = "#{input.split.first} '#{input.split[1..-1].join(' ')}'" # making it like >> When 'I do this and that'
85
+ world.instance_eval input
86
+ end
87
+
88
+
89
+ ## HELPERS
90
+
91
+ def feature_file
92
+ @feature_file ||= File.join(Rails.root, scenario.file_colon_line.split(":").first)
93
+ end
94
+
95
+ def spaces_in_last_line
96
+ for line in File.readlines(feature_file).reverse
97
+ unless line.blank?
98
+ spaces = line =~ /\S/
99
+ return spaces
100
+ end
101
+ end
102
+
103
+ 0
104
+ end
105
+ end
@@ -1,3 +1,3 @@
1
1
  module Cucumberator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumberator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-14 00:00:00.000000000Z
12
+ date: 2011-09-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
16
- requirement: &18874660 !ruby/object:Gem::Requirement
16
+ requirement: &9675260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18874660
24
+ version_requirements: *9675260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cucumber-rails
27
- requirement: &18868820 !ruby/object:Gem::Requirement
27
+ requirement: &9674100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.0.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18868820
35
+ version_requirements: *9674100
36
36
  description: Prompt for writing Cucumber tests
37
37
  email:
38
38
  - vidmantas@kabosis.lt
@@ -47,14 +47,14 @@ files:
47
47
  - Rakefile
48
48
  - cucumberator.gemspec
49
49
  - lib/cucumberator.rb
50
- - lib/cucumberator/cucumberize.rb
50
+ - lib/cucumberator/cucumberizator.rb
51
51
  - lib/cucumberator/version.rb
52
52
  homepage: https://github.com/vidmantas/cucumberator
53
53
  licenses: []
54
54
  post_install_message: ! '(::)
55
55
 
56
- Cucumberator installed! Now require cucumberator/cucumberize in your env.rb and
57
- place @cucumberize before the scenario you''d like to append new steps
56
+ Cucumberator installed! Now require cucumberator in your env.rb and place @cucumberize
57
+ before the scenario you''d like to append new steps
58
58
 
59
59
  (::)'
60
60
  rdoc_options: []
@@ -77,5 +77,5 @@ rubyforge_project:
77
77
  rubygems_version: 1.8.10
78
78
  signing_key:
79
79
  specification_version: 3
80
- summary: cucumberator-0.0.1
80
+ summary: cucumberator-0.0.2
81
81
  test_files: []
@@ -1,60 +0,0 @@
1
- After('@cucumberize') do |s|
2
- if s.failed?
3
- puts "Sorry, no cucumberator when scenario is already failing!"
4
- return
5
- end
6
-
7
- last_input = nil
8
-
9
- while true
10
- print "> "
11
- input = STDIN.gets.chomp
12
-
13
- begin
14
- case input
15
- when "exit"
16
- break
17
-
18
- when "exit-all"
19
- Cucumber.wants_to_quit = true
20
- break
21
-
22
- when "help"
23
- puts %{
24
- Write a step directly here and watch it happen on the browser
25
- Available commands:
26
- save - saves last step into current feature file
27
- last-step - display last executed step
28
- exit - exits current step
29
- exit-all - exists whole Cucumber feature
30
- help - display this notification
31
- }
32
-
33
- when "last-step"
34
- puts last_input
35
-
36
- when "save"
37
- if last_input.blank?
38
- puts "Hm... nothing to save yet?"
39
- else
40
- feature_file = File.join(Rails.root, s.file_colon_line.split(":").first)
41
- spaces = File.readlines(feature_file)[-1] =~ /\S/
42
- File.open(feature_file, 'a') do |f|
43
- f.puts((" " * spaces) + last_input)
44
- last_input = nil
45
- end
46
-
47
- puts "Saved to #{feature_file}"
48
- end
49
-
50
- else
51
- last_input = input
52
- input = "#{input.split.first} '#{input.split[1..-1].join(' ')}'"
53
- puts input
54
- instance_eval input
55
- end
56
- rescue Exception => e
57
- puts e.inspect
58
- end
59
- end
60
- end