cucumberator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -7
- data/cucumberator.gemspec +1 -1
- data/lib/cucumberator/current_step.rb +19 -0
- data/lib/cucumberator/version.rb +1 -1
- data/lib/cucumberator/writer.rb +169 -0
- data/lib/cucumberator.rb +16 -2
- metadata +11 -10
- data/lib/cucumberator/cucumberizator.rb +0 -105
data/README.md
CHANGED
@@ -2,9 +2,14 @@ Cucumberator is Cucumber extension to write steps in command line, whatch how br
|
|
2
2
|
|
3
3
|
## How to use
|
4
4
|
|
5
|
-
* Put @cucumberize tag in front of Scenario you want to append with new steps
|
6
|
-
*
|
7
|
-
*
|
5
|
+
* Put @cucumberize tag in front of empty Scenario you want to append with new steps.
|
6
|
+
* Or place step "Then I will write new steps" anywhere in scenario.
|
7
|
+
* Fire up the cucumber and wait until prompt shows up.
|
8
|
+
* Write a step, watch it happen on the browser!
|
9
|
+
|
10
|
+
All steps are **automatically saved** into .feature file unless it's unsuccessful. If you're unhappy with the last step, type "undo". See all commands with "help".
|
11
|
+
|
12
|
+
If you have Continuous Integration, do not forget to remove cucumberator tag/step before pushing! ;-)
|
8
13
|
|
9
14
|
## Installation
|
10
15
|
|
@@ -20,17 +25,21 @@ Then require it in one of your ruby files under features/support (e.g. env.rb)
|
|
20
25
|
|
21
26
|
require 'cucumberator'
|
22
27
|
|
23
|
-
Now
|
28
|
+
Now use special step in any place:
|
29
|
+
|
30
|
+
# ...some steps...
|
31
|
+
Then I will write new steps
|
32
|
+
# ...can be the end or other steps...
|
33
|
+
|
34
|
+
or put @cucumberize before last **empty** Scenario you want to fill up, for example
|
24
35
|
|
25
36
|
@javascript @cucumberize
|
26
37
|
Scenario: check fancy ajax login
|
27
|
-
Given user with email some@example.com
|
28
38
|
|
29
|
-
and then run this feature file
|
39
|
+
and then run this feature file, watch your console for prompt to show up. Enjoy writing steps on the go!
|
30
40
|
|
31
41
|
## TODO
|
32
42
|
|
33
|
-
* support of multiple scenarios per feature file
|
34
43
|
* autocomplete for available steps
|
35
44
|
* tests
|
36
45
|
|
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 in your env.rb and
|
13
|
+
s.post_install_message = "(::)\nCucumberator installed! Now require cucumberator in your env.rb and check README for usage examples\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")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cucumberator
|
2
|
+
class CurrentStep
|
3
|
+
attr_accessor :line
|
4
|
+
|
5
|
+
def initialize(scenario)
|
6
|
+
@scenario_sexp = scenario.instance_variable_get("@steps").to_sexp
|
7
|
+
end
|
8
|
+
|
9
|
+
def increase
|
10
|
+
if self.line
|
11
|
+
@offset += 1
|
12
|
+
else
|
13
|
+
@offset = 0
|
14
|
+
end
|
15
|
+
|
16
|
+
self.line = @scenario_sexp[@offset][1]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/cucumberator/version.rb
CHANGED
@@ -0,0 +1,169 @@
|
|
1
|
+
module Cucumberator
|
2
|
+
class Writer
|
3
|
+
attr_accessor :world, :scenario, :step_line, :original_step_line, :last_input, :exit_flag, :saved_stack
|
4
|
+
|
5
|
+
FULL_BACKTRACE = false
|
6
|
+
|
7
|
+
def initialize(world, scenario, step_line = nil)
|
8
|
+
@world, @scenario = world, scenario
|
9
|
+
@step_line = @original_step_line = step_line if step_line
|
10
|
+
@saved_stack = []
|
11
|
+
|
12
|
+
check_scenario
|
13
|
+
set_autocomplete
|
14
|
+
read_input
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_scenario
|
18
|
+
raise "Sorry, no cucumberator when scenario is already failing!" if scenario.failed?
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_autocomplete
|
22
|
+
commands = %w(exit exit-all help last-step save undo)
|
23
|
+
Readline.completion_proc = proc{|s| commands.grep( /^#{Regexp.escape(s)}/ ) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_input
|
27
|
+
input = Readline.readline("> ", true)
|
28
|
+
parse_input(input)
|
29
|
+
read_input unless exit_flag
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_input(input)
|
33
|
+
case input
|
34
|
+
when "exit"
|
35
|
+
self.exit_flag = true and return
|
36
|
+
|
37
|
+
when "exit-all"
|
38
|
+
Cucumber.wants_to_quit = true
|
39
|
+
self.exit_flag = true and return
|
40
|
+
|
41
|
+
when "help"
|
42
|
+
display_help
|
43
|
+
|
44
|
+
when "last-step"
|
45
|
+
puts last_input
|
46
|
+
|
47
|
+
when "save"
|
48
|
+
save_last_input
|
49
|
+
|
50
|
+
when "undo"
|
51
|
+
undo
|
52
|
+
|
53
|
+
when ""
|
54
|
+
save_empty_line
|
55
|
+
|
56
|
+
else
|
57
|
+
begin
|
58
|
+
execute_cucumber_step(input)
|
59
|
+
save_last_input
|
60
|
+
rescue Exception => e
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
rescue Exception => e
|
66
|
+
puts e.inspect
|
67
|
+
puts e.backtrace.join("\n") if FULL_BACKTRACE
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
## COMMANDS
|
72
|
+
|
73
|
+
def display_help
|
74
|
+
puts ":: Write a step here and watch it happen on the browser."
|
75
|
+
puts ":: Steps are automatically saved unless it raises exception. Use 'save' to force-save it anyway."
|
76
|
+
puts ":: Available commands:"
|
77
|
+
puts ":: save - force-saves last step into current feature file"
|
78
|
+
puts ":: last-step - display last executed step (to be saved on 'save' command)"
|
79
|
+
puts ":: undo - remove last saved line from feature file"
|
80
|
+
puts ":: exit - exits current scenario"
|
81
|
+
puts ":: exit-all - exists whole Cucumber feature"
|
82
|
+
puts ":: help - display this notification"
|
83
|
+
end
|
84
|
+
|
85
|
+
def save_last_input
|
86
|
+
if last_input.blank?
|
87
|
+
puts "Hm... nothing to save yet?"
|
88
|
+
else
|
89
|
+
string_to_save = (" " * spaces_in_last_input) + last_input
|
90
|
+
save_to_feature_file(string_to_save)
|
91
|
+
|
92
|
+
puts "Saved \"#{last_input}\" to #{File.basename(feature_file)}"
|
93
|
+
self.last_input = nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def save_to_feature_file(string)
|
98
|
+
if step_line
|
99
|
+
feature_file_lines = File.readlines(feature_file)
|
100
|
+
feature_file_lines.insert(step_line, string.to_s+$/) # $/ - default newline separator
|
101
|
+
File.open(feature_file, 'w'){|f| f.puts(feature_file_lines.join) }
|
102
|
+
self.step_line += 1
|
103
|
+
else
|
104
|
+
File.open(feature_file, 'a'){|f| f.puts(string) }
|
105
|
+
end
|
106
|
+
|
107
|
+
self.saved_stack << string
|
108
|
+
end
|
109
|
+
|
110
|
+
def save_empty_line
|
111
|
+
save_to_feature_file("")
|
112
|
+
self.last_input = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def execute_cucumber_step(input)
|
116
|
+
return if input.blank?
|
117
|
+
|
118
|
+
self.last_input = input
|
119
|
+
world.steps(input)
|
120
|
+
end
|
121
|
+
|
122
|
+
def undo
|
123
|
+
if saved_stack.empty?
|
124
|
+
puts "There's nothing to revert yet" and return
|
125
|
+
end
|
126
|
+
|
127
|
+
feature_file_lines = File.readlines(feature_file)
|
128
|
+
|
129
|
+
removed = if step_line
|
130
|
+
self.step_line -= 1
|
131
|
+
feature_file_lines.delete_at(step_line)
|
132
|
+
else
|
133
|
+
feature_file_lines.pop
|
134
|
+
end
|
135
|
+
|
136
|
+
puts "Removed \"#{removed.to_s.strip}\" from #{File.basename(feature_file)}"
|
137
|
+
|
138
|
+
File.open(feature_file, 'w'){|f| f.puts(feature_file_lines.join) }
|
139
|
+
self.saved_stack.pop
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
## HELPERS
|
144
|
+
|
145
|
+
def feature_file
|
146
|
+
@feature_file ||= File.join(Rails.root, scenario.file_colon_line.split(":").first)
|
147
|
+
end
|
148
|
+
|
149
|
+
def spaces_in_last_input
|
150
|
+
spaces = 0
|
151
|
+
lines = File.readlines(feature_file)
|
152
|
+
|
153
|
+
if step_line
|
154
|
+
line = lines[step_line-1]
|
155
|
+
else
|
156
|
+
for l in lines.reverse
|
157
|
+
unless l.blank?
|
158
|
+
line = l
|
159
|
+
break
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
spaces = line =~ /\S/
|
165
|
+
spaces
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
data/lib/cucumberator.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
require "readline"
|
2
|
-
require "cucumberator/
|
2
|
+
require "cucumberator/current_step"
|
3
|
+
require "cucumberator/writer"
|
3
4
|
|
4
5
|
After('@cucumberize') do |scenario|
|
5
|
-
|
6
|
+
Cucumberator::Writer.new(self, scenario)
|
7
|
+
end
|
8
|
+
|
9
|
+
Before do |scenario|
|
10
|
+
@current_cucumberator_scenario = scenario
|
11
|
+
@current_step = Cucumberator::CurrentStep.new(scenario)
|
12
|
+
end
|
13
|
+
|
14
|
+
AfterStep do
|
15
|
+
@current_step.increase
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^I will write new steps$/ do
|
19
|
+
Cucumberator::Writer.new(self, @current_cucumberator_scenario, @current_step.line)
|
6
20
|
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.
|
4
|
+
version: 0.0.3
|
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-
|
12
|
+
date: 2011-09-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
16
|
-
requirement: &
|
16
|
+
requirement: &7267520 !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: *
|
24
|
+
version_requirements: *7267520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cucumber-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &7265160 !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: *
|
35
|
+
version_requirements: *7265160
|
36
36
|
description: Prompt for writing Cucumber tests
|
37
37
|
email:
|
38
38
|
- vidmantas@kabosis.lt
|
@@ -47,14 +47,15 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- cucumberator.gemspec
|
49
49
|
- lib/cucumberator.rb
|
50
|
-
- lib/cucumberator/
|
50
|
+
- lib/cucumberator/current_step.rb
|
51
51
|
- lib/cucumberator/version.rb
|
52
|
+
- lib/cucumberator/writer.rb
|
52
53
|
homepage: https://github.com/vidmantas/cucumberator
|
53
54
|
licenses: []
|
54
55
|
post_install_message: ! '(::)
|
55
56
|
|
56
|
-
Cucumberator installed! Now require cucumberator in your env.rb and
|
57
|
-
|
57
|
+
Cucumberator installed! Now require cucumberator in your env.rb and check README
|
58
|
+
for usage examples
|
58
59
|
|
59
60
|
(::)'
|
60
61
|
rdoc_options: []
|
@@ -77,5 +78,5 @@ rubyforge_project:
|
|
77
78
|
rubygems_version: 1.8.10
|
78
79
|
signing_key:
|
79
80
|
specification_version: 3
|
80
|
-
summary: cucumberator-0.0.
|
81
|
+
summary: cucumberator-0.0.3
|
81
82
|
test_files: []
|
@@ -1,105 +0,0 @@
|
|
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
|