Class: Cucumber::CLI

Inherits:
Object show all
Defined in:
lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb

Constant Summary collapse

FORMATS =
%w{pretty profile progress html autotest}
DEFAULT_FORMAT =
'pretty'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out_stream = STDOUT, error_stream = STDERR) ⇒ CLI

Returns a new instance of CLI.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 32

def initialize(out_stream = STDOUT, error_stream = STDERR)
  @out_stream = out_stream
  @error_stream = error_stream
  @paths = []
  @options = {
    :require => nil,
    :lang    => 'en',
    :dry_run => false,
    :source  => true,
    :snippets => true,
    :formats => {},
    :excludes => [],
    :scenario_names => nil
  }
  @active_format = DEFAULT_FORMAT
end

Class Attribute Details

.executor=(value) ⇒ Object (writeonly)

Sets the attribute executor

Parameters:

  • value

    the value to set the attribute executor to.



10
11
12
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 10

def executor=(value)
  @executor = value
end

.features=(value) ⇒ Object (writeonly)

Sets the attribute features

Parameters:

  • value

    the value to set the attribute features to.



10
11
12
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 10

def features=(value)
  @features = value
end

.step_mother=(value) ⇒ Object (writeonly)

Sets the attribute step_mother

Parameters:

  • value

    the value to set the attribute step_mother to.



10
11
12
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 10

def step_mother=(value)
  @step_mother = value
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



28
29
30
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 28

def options
  @options
end

#pathsObject (readonly)

Returns the value of attribute paths.



28
29
30
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 28

def paths
  @paths
end

Class Method Details

.execute(args) ⇒ Object



12
13
14
15
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 12

def execute(args)
  @execute_called = true
  parse(args).execute!(@step_mother, @executor, @features)
end

.execute_called?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 17

def execute_called?
  @execute_called
end

.parse(args) ⇒ Object



21
22
23
24
25
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 21

def parse(args)
  cli = new
  cli.parse_options!(args)
  cli
end

Instance Method Details

#execute!(step_mother, executor, features) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 150

def execute!(step_mother, executor, features)
  Term::ANSIColor.coloring = @options[:color] unless @options[:color].nil?
  Cucumber.load_language(@options[:lang])
  require_files
  enable_diffing
  executor.formatters = build_formatter_broadcaster(step_mother)
  load_plain_text_features(features)
  executor.lines_for_features = @options[:lines_for_features]
  executor.scenario_names = @options[:scenario_names] if @options[:scenario_names]
  executor.visit_features(features)
  exit 1 if executor.failed
end

#parse_options!(args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/cli.rb', line 49

def parse_options!(args)
  @args = args
  return parse_args_from_profile('default') if args.empty?
  args.extend(OptionParser::Arguable)

  args.options do |opts|
    opts.banner = ["Usage: cucumber [options] [[FILE[:LINE[:LINE]*]] | [FILES|DIRS]]", "",
      "Examples:",
      "cucumber examples/i18n/en/features",
      "cucumber --language it examples/i18n/it/features/somma.feature:6:98:113", "", ""
    ].join("\n")
    opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR", "Require files before executing the features.",
      "If this option is not specified, all *.rb files that",
      "are siblings or below the features will be autorequired",
      "This option can be specified multiple times.") do |v|
      @options[:require] ||= []
      @options[:require] << v
    end
    opts.on("-s SCENARIO", "--scenario SCENARIO", "Only execute the scenario with the given name.",
                                                  "If this option is given more than once, run all",
                                                  "the specified scenarios.") do |v|
      @options[:scenario_names] ||= []
      @options[:scenario_names] << v
    end
    opts.on("-l LANG", "--language LANG", "Specify language for features (Default: #{@options[:lang]})",
      "Available languages: #{Cucumber.languages.join(", ")}",
      "Look at #{Cucumber::LANGUAGE_FILE} for keywords") do |v|
      @options[:lang] = v
    end
    opts.on("-f FORMAT", "--format FORMAT", "How to format features (Default: #{DEFAULT_FORMAT})",
      "Available formats: #{FORMATS.join(", ")}",
      "You can also provide your own formatter classes as long as they have been",
      "previously required using --require or if they are in the folder",
      "structure such that cucumber will require them automatically.",
      "This option can be specified multiple times.") do |v|
  
      @options[:formats][v] ||= []
      @options[:formats][v] << @out_stream
      @active_format = v
    end
    opts.on("-o", "--out FILE", "Write output to a file instead of @out_stream.",
      "This option can be specified multiple times, and applies to the previously",
      "specified --format.") do |v|
      @options[:formats][@active_format] ||= []
      if @options[:formats][@active_format].last == @out_stream
        @options[:formats][@active_format][-1] = File.open(v, 'w')
      else
        @options[:formats][@active_format] << File.open(v, 'w')
      end
    end
    opts.on("-c", "--[no-]color", "Use ANSI color in the output, if formatters use it.  If",
                                  "these options are given multiple times, the last one is",
                                  "used.  If neither --color or --no-color is given cucumber",
                                  "decides based on your platform and the output destination") do |v|
      @options[:color] = v
    end
    opts.on("-e", "--exclude PATTERN", "Don't run features matching a pattern") do |v|
      @options[:excludes] << v
    end
    opts.on("-p", "--profile PROFILE", "Pull commandline arguments from cucumber.yml.") do |v|
      parse_args_from_profile(v)
    end
    opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.") do
      @options[:dry_run] = true
    end
    opts.on("-n", "--no-source", "Don't show the file and line of the step definition with the steps.") do
      @options[:source] = false
    end
    opts.on("-i", "--no-snippets", "Don't show the snippets for pending steps") do
      @options[:snippets] = false
    end
    opts.on("-q", "--quiet", "Don't show any development aid information") do
      @options[:snippets] = false
      @options[:source] = false
    end
    opts.on("-b", "--backtrace", "Show full backtrace for all errors") do
      Exception.cucumber_full_backtrace = true
    end
    opts.on("-v", "--verbose", "Show the files and features loaded") do
      @options[:verbose] = true
    end
    opts.on_tail("--version", "Show version") do
      @out_stream.puts VERSION::STRING
      Kernel.exit
    end
    opts.on_tail("--help", "You're looking at it") do
      @out_stream.puts opts.help
      Kernel.exit
    end
  end.parse!

  if @options[:formats].empty?
    @options[:formats][DEFAULT_FORMAT] = [@out_stream]
  end
  
  # Whatever is left after option parsing is the FILE arguments
  args = extract_and_store_line_numbers(args)
  @paths += args
end