Class: Bolt::Runners::Cucumber
- Defined in:
- lib/bolt/runners/cucumber.rb
Constant Summary collapse
- MAPPINGS =
mappings define which folders hold the files that the listener should listen to
/(\.\/app\/|\.\/lib\/|\.\/features\/)/- CLASS_MAP =
class map specifies the folders holding classes that can be reloaded
/(app\/controllers\/|app\/models\/|lib\/)/- @@mother =
step mother storage
nil
Instance Attribute Summary collapse
-
#controllers ⇒ Object
Returns the value of attribute controllers.
-
#heard ⇒ Object
Returns the value of attribute heard.
-
#models ⇒ Object
Returns the value of attribute models.
-
#notifier ⇒ Object
Returns the value of attribute notifier.
-
#test_io ⇒ Object
Returns the value of attribute test_io.
Class Method Summary collapse
-
.mother ⇒ Object
Get the referenced StepMother.
-
.mother=(step_mother) ⇒ Object
Save a reference for supplied StepMother.
Instance Method Summary collapse
-
#initialize ⇒ Cucumber
constructor
Create a new Cucumber Runner.
-
#read_map ⇒ Object
Read the feature map located in .bolt file.
-
#run(features) ⇒ Object
Run an array of feature files.
-
#translate(file) ⇒ Object
Translate a filename into an array of feature filenames.
Methods inherited from Base
#clear_class, #file_verified?, #handle, #initialized, #load_file, #reload, #resolve_class, #resolve_classname
Constructor Details
#initialize ⇒ Cucumber
Create a new Cucumber Runner
32 33 34 35 36 |
# File 'lib/bolt/runners/cucumber.rb', line 32 def initialize self.controllers = {} self.models = {} read_map end |
Instance Attribute Details
#controllers ⇒ Object
Returns the value of attribute controllers.
16 17 18 |
# File 'lib/bolt/runners/cucumber.rb', line 16 def controllers @controllers end |
#heard ⇒ Object
Returns the value of attribute heard.
16 17 18 |
# File 'lib/bolt/runners/cucumber.rb', line 16 def heard @heard end |
#models ⇒ Object
Returns the value of attribute models.
16 17 18 |
# File 'lib/bolt/runners/cucumber.rb', line 16 def models @models end |
#notifier ⇒ Object
Returns the value of attribute notifier.
16 17 18 |
# File 'lib/bolt/runners/cucumber.rb', line 16 def notifier @notifier end |
#test_io ⇒ Object
Returns the value of attribute test_io.
16 17 18 |
# File 'lib/bolt/runners/cucumber.rb', line 16 def test_io @test_io end |
Class Method Details
.mother ⇒ Object
Get the referenced StepMother
27 28 29 |
# File 'lib/bolt/runners/cucumber.rb', line 27 def self.mother @@mother end |
.mother=(step_mother) ⇒ Object
Save a reference for supplied StepMother
22 23 24 |
# File 'lib/bolt/runners/cucumber.rb', line 22 def self.mother=(step_mother) @@mother = step_mother end |
Instance Method Details
#read_map ⇒ Object
Read the feature map located in .bolt file
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/bolt/runners/cucumber.rb', line 39 def read_map if !Bolt['feature_map'] puts "** ERROR: could not find feature_map in .bolt" else Bolt['feature_map'].each do |feature, map| # controllers if map["controllers"].include?(',') map["controllers"].split(',').each { |controller| name = controller.strip self.controllers[name] = [] if !self.controllers[name] self.controllers[name] << feature } else name = map["controllers"] self.controllers[name] = [] if !self.controllers[name] self.controllers[name] << feature end # models if map["models"].include?(',') map["models"].split(',').each { |model| name = model.strip self.models[name] = [] if !self.models[name] self.models[name] << feature } else name = map["models"] self.models[name] = [] if !self.models[name] self.models[name] << feature end end end end |
#run(features) ⇒ Object
Run an array of feature files
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 148 149 150 151 152 153 |
# File 'lib/bolt/runners/cucumber.rb', line 118 def run(features) # redirect spec output to StringIO io = StringIO.new $stdout, old = io, $stdout # refresh the loaded test file #$".delete(file) #require file if Bolt::Runners::Cucumber.mother and self.heard.match('_steps.rb') #puts '=> reloading step definitions' #Bolt::Runners::Cucumber.mother.reload_definitions! end ::Cucumber::Cli::Main.execute(features) Bolt::Runners::Cucumber.mother.clear_steps_and_scenarios! # read the buffer result = io.string.to_s.dup $stdout = old # send buffer to stdout puts result if result.include?('You can implement step definitions') result = result.split('You can implement step definitions').first end last_three = result.split("\n")[-3..-1].join(' ') last_three = last_three.gsub("\e[32m", '').gsub("\e[0m", '').gsub("\e[36m", '').gsub("\e[31m", '').gsub("\e[33m", '') # get ri of the color codes # sent result to notifier notifier.result(features.join(' '), last_three) end |
#translate(file) ⇒ Object
Translate a filename into an array of feature filenames
This is a modified version of mislav/rspactor Inspector#translate
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 |
# File 'lib/bolt/runners/cucumber.rb', line 78 def translate(file) self.heard = file puts file case file when %r:^app/controllers/: name = file.sub('_controller.rb', '').sub('app/controllers/', '') features = self.controllers[name] when %r:^app/models/: name = file.sub('.rb', '').sub('app/models/', '') features = self.models[name] # when %r:^app/views/: file = file.sub('app/views/', '') directory = file.split('/')[0..-2].compact.join('/') features = self.controllers[directory] when %r:^lib/: name = file.sub('.rb', '').sub('lib/', '') features = self.models[name] when %r:.feature$: return [file] when %r:steps.rb$: if Bolt::Runners::Cucumber.mother puts '=> reloading step definitions' Bolt::Runners::Cucumber.mother.reload_definitions! end features = [file.gsub('features/step_definitions/', '').gsub('_steps.rb', '')] else # end features = [] if !features return features.collect { |name| "features/#{name}.feature" } end |