Class: Cucumber::Cli::Main

Inherits:
Object show all
Defined in:
lib/cucumber/cli/main.rb

Constant Summary collapse

FAILURE =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, out_stream = STDOUT, error_stream = STDERR) ⇒ Main

Returns a new instance of Main.



32
33
34
35
36
# File 'lib/cucumber/cli/main.rb', line 32

def initialize(args, out_stream = STDOUT, error_stream = STDERR)
  @args         = args
  @out_stream   = out_stream == STDOUT ? Formatter::ColorIO.new : out_stream
  @error_stream = error_stream
end

Class Method Details

.execute(args) ⇒ Object



27
28
29
# File 'lib/cucumber/cli/main.rb', line 27

def execute(args)
  new(args).execute!(@step_mother)
end

.step_motherObject



17
18
19
# File 'lib/cucumber/cli/main.rb', line 17

def step_mother
  @step_mother
end

.step_mother=(step_mother) ⇒ Object



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

def step_mother=(step_mother)
  @step_mother = step_mother
  @step_mother.extend(StepMother)
  @step_mother.snippet_generator = StepDefinition
end

Instance Method Details

#configurationObject



103
104
105
106
107
108
109
# File 'lib/cucumber/cli/main.rb', line 103

def configuration
  return @configuration if @configuration

  @configuration = Configuration.new(@out_stream, @error_stream)
  @configuration.parse!(@args)
  @configuration
end

#exceeded_tag_limts?(features) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cucumber/cli/main.rb', line 74

def exceeded_tag_limts?(features)
  exceeded = false
  configuration.options[:include_tags].each do |tag, limit|
    unless limit.nil?
      tag_count = features.tag_count(tag)
      if tag_count > limit.to_i
        exceeded = true
      end
    end
  end
  exceeded
end

#execute!(step_mother) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cucumber/cli/main.rb', line 38

def execute!(step_mother)
  trap_interrupt
  if configuration.drb?
    begin
      return DRbClient.run(@args, @error_stream, @out_stream)
    rescue DRbClientError => e
      @error_stream.puts "WARNING: #{e.message} Running features locally:"
    end
  end
  step_mother.options = configuration.options

  # Feature files must be loaded before files are required.
  # This is because i18n step methods are only aliased when
  # features are loaded. If we swap the order, the requires
  # will fail.
  features = load_plain_text_features
  require_files
  enable_diffing

  visitor = configuration.build_formatter_broadcaster(step_mother)
  step_mother.visitor = visitor # Needed to support World#announce
  visitor.visit_features(features)

  failure = if exceeded_tag_limts?(features)
      FAILURE
    elsif configuration.wip?
      step_mother.scenarios(:passed).any?
    else
      step_mother.scenarios(:failed).any? ||
      (configuration.strict? && step_mother.steps(:undefined).any?)
    end
rescue ProfilesNotDefinedError, YmlLoadError, ProfileNotFound => e
  @error_stream.puts e.message
  true
end

#load_filesObject



111
112
113
# File 'lib/cucumber/cli/main.rb', line 111

def load_files
  each_lib{|lib| load(lib)}
end

#load_plain_text_featuresObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cucumber/cli/main.rb', line 87

def load_plain_text_features
  features = Ast::Features.new

  verbose_log("Features:")
  configuration.feature_files.each do |f|
    feature_file = FeatureFile.new(f)
    feature = feature_file.parse(configuration.options)
    if feature
      features.add_feature(feature)
      verbose_log("  * #{f}")
    end
  end
  verbose_log("\n"*2)
  features
end