class Cucumberator::Commands::Save
Attributes
saved_stack[RW]
step_line[RW]
Public Class Methods
new(scenario, step_line, last_input, saved_stack)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 17 def initialize(scenario, step_line, last_input, saved_stack) @step_line, @last_input, @saved_stack = step_line, last_input, saved_stack @feature_file = Cucumberator::FeatureFile.new(scenario) @scenario_line = scenario.line - 1 end
perform(scenario, step_line, last_input, saved_stack, *args, &block)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 4 def perform(scenario, step_line, last_input, saved_stack, *args, &block) new(scenario, step_line, last_input, saved_stack).save false end
save_empty_line(scenario, step_line, saved_stack)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 9 def save_empty_line(scenario, step_line, saved_stack) new(scenario, step_line, "", saved_stack).force_save_empty_line false end
Public Instance Methods
append_line_to_feature_file(line)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 57 def append_line_to_feature_file(line) @feature_file.append(line) self.saved_stack << [@feature_file.lines.size, line] end
detect_last_line(lines)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 78 def detect_last_line(lines) if step_line line = lines[step_line-1] lines = lines.slice(0, step_line-1) if line.to_s.empty? end if line.to_s.empty? line = lines.reverse.detect { |l| !l.to_s.empty? } end line end
force_save_empty_line()
click to toggle source
# File lib/cucumberator/commands/save.rb, line 35 def force_save_empty_line save_to_feature_file("") @last_input = nil end
insert_line_to_feature_file(line)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 48 def insert_line_to_feature_file(line) lines = @feature_file.lines lines.insert(step_line - 1, line.to_s+$/) # $/ - default newline separator @feature_file.overwrite(lines.join) self.saved_stack << [step_line.number, line] self.step_line.increment! end
parent_scenario_spacing()
click to toggle source
# File lib/cucumberator/commands/save.rb, line 70 def parent_scenario_spacing @parent_depth ||= @feature_file.lines[@scenario_line] =~ /\S/ end
save()
click to toggle source
# File lib/cucumberator/commands/save.rb, line 23 def save if @last_input.to_s.empty? puts "Hm... nothing to save yet?" else string_to_save = (" " * spaces_in_last_input) + @last_input save_to_feature_file(string_to_save) puts "Saved `#{@last_input}` to #{@feature_file}" @last_input = nil end end
save_to_feature_file(line)
click to toggle source
# File lib/cucumberator/commands/save.rb, line 40 def save_to_feature_file(line) if step_line insert_line_to_feature_file(line) else append_line_to_feature_file(line) end end
scenario_child_spacing()
click to toggle source
# File lib/cucumberator/commands/save.rb, line 74 def scenario_child_spacing @child_depth ||= parent_scenario_spacing + 2 end
spaces_in_last_input()
click to toggle source
# File lib/cucumberator/commands/save.rb, line 62 def spaces_in_last_input return scenario_child_spacing unless step_line line = detect_last_line(@feature_file.lines) spaces = line.to_s =~ /\S/ spaces.to_i end