Best Spinach_ruby code snippet using Spinach.feature_files
cli_test.rb
Source:cli_test.rb
2describe Spinach::Cli do3 describe '#run' do4 it 'gets the options and runs the features' do5 cli = Spinach::Cli.new(['features/some_feature.feature'])6 cli.stubs(:feature_files).returns(['features/some_feature.feature'])7 cli.expects(:options)8 Spinach::Runner.any_instance.expects(:run)9 cli.run10 end11 end12 describe '#options' do13 it 'sets the default options' do14 config = Spinach::Config.new15 Spinach.stubs(:config).returns(config)16 cli = Spinach::Cli.new([])17 cli.options18 config[:reporter_options].must_equal({})19 end20 it 'sets the default fail-fast option to false' do21 config = Spinach::Config.new22 Spinach.stubs(:config).returns(config)23 cli = Spinach::Cli.new([])24 cli.options25 config[:fail_fast].wont_equal(true)26 end27 it 'sets default tags' do28 config = Spinach::Config.new29 Spinach.stubs(:config).returns(config)30 cli = Spinach::Cli.new([])31 cli.options32 config[:tags].must_equal [['~wip']]33 end34 it 'sets default tags some are defined in config file' do35 in_current_dir do36 config = Spinach::Config.new37 config.config_path = "spinach.yml"38 File.open(config.config_path, "w") do |f|39 f.write <<-EOS40---41tags:42 - v143 - - ~external44 - js45 EOS46 end47 Spinach.stubs(:config).returns(config)48 cli = Spinach::Cli.new([])49 cli.options50 config[:tags].must_equal [['~wip'], 'v1', ['~external', 'js']]51 end52 end53 describe 'backtrace' do54 %w{-b --backtrace}.each do |opt|55 it 'sets the backtrace if #{opt}' do56 config = Spinach::Config.new57 Spinach.stubs(:config).returns(config)58 cli = Spinach::Cli.new([opt])59 cli.options60 config[:reporter_options][:backtrace].must_equal true61 end62 end63 end64 describe 'reporter class' do65 %w{-r --reporter}.each do |opt|66 it 'sets the reporter class' do67 config = Spinach::Config.new68 Spinach.stubs(:config).returns(config)69 cli = Spinach::Cli.new([opt, 'progress'])70 cli.options71 config.reporter_classes.must_equal ['Spinach::Reporter::Progress']72 end73 it 'sets multiple reporter classes' do74 config = Spinach::Config.new75 Spinach.stubs(:config).returns(config)76 cli = Spinach::Cli.new([opt, 'progress,stdout'])77 cli.options78 config.reporter_classes.must_equal ['Spinach::Reporter::Progress', 'Spinach::Reporter::Stdout']79 end80 end81 end82 describe 'rand' do83 let(:config) { Spinach::Config.new }84 before do85 Spinach.stubs(:config).returns(config)86 Spinach::Cli.new(%w(--rand)).options87 end88 it 'uses the Random orderer' do89 config.orderer_class.must_equal 'Spinach::Orderers::Random'90 end91 it 'sets a numeric seed' do92 config.seed.must_equal config.seed.to_i93 end94 end95 describe 'seed' do96 let(:config) { Spinach::Config.new }97 before do98 Spinach.stubs(:config).returns(config)99 Spinach::Cli.new(%w(--seed 42)).options100 end101 it 'uses the random orderer' do102 config.orderer_class.must_equal 'Spinach::Orderers::Random'103 end104 it 'sets the seed' do105 config.seed.must_equal 42106 end107 end108 describe 'features_path' do109 %w{-f --features_path}.each do |opt|110 it 'sets the given features_path' do111 config = Spinach::Config.new112 Spinach.stubs(:config).returns(config)113 cli = Spinach::Cli.new([opt,"custom_path"])114 cli.options115 config.features_path.must_equal 'custom_path'116 end117 end118 end119 describe 'tags' do120 %w{-t --tags}.each do |opt|121 it 'sets the given tag' do122 config = Spinach::Config.new123 Spinach.stubs(:config).returns(config)124 cli = Spinach::Cli.new([opt,'wip'])125 cli.options126 config.tags.must_equal [['wip']]127 end128 it 'sets OR-ed tags' do129 config = Spinach::Config.new130 Spinach.stubs(:config).returns(config)131 cli = Spinach::Cli.new([opt,'wip,javascript'])132 cli.options133 config.tags.must_equal [['wip', 'javascript']]134 end135 it 'adds ~wip by default' do136 config = Spinach::Config.new137 Spinach.stubs(:config).returns(config)138 cli = Spinach::Cli.new([opt,'javascript'])139 cli.options140 config.tags.must_equal [['~wip', 'javascript']]141 end142 it 'has precedence over tags specified in config file' do143 in_current_dir do144 config = Spinach::Config.new145 config.config_path = "spinach.yml"146 File.open(config.config_path, "w") do |f|147 f.write <<-EOS148---149tags:150 - v1151 EOS152 end153 Spinach.stubs(:config).returns(config)154 cli = Spinach::Cli.new([opt,'javascript'])155 cli.options156 config[:tags].must_equal [['~wip', 'javascript']]157 end158 end159 end160 it 'sets AND-ed tags' do161 config = Spinach::Config.new162 Spinach.stubs(:config).returns(config)163 cli = Spinach::Cli.new(['-t','javascript', '-t', 'wip'])164 cli.options165 config.tags.must_equal [['~wip', 'javascript'],['wip']]166 end167 end168 describe 'generate' do169 %w{-g --generate}.each do |generate_opt|170 it 'inits the generator if #{generate_opt}' do171 config = Spinach::Config.new172 Spinach.stubs(:config).returns(config)173 Spinach::Generators.expects(:run)174 Spinach::Cli.new([generate_opt]).run175 config.generate.must_equal true176 end177 %w{-f --features_path}.each do |feature_path_opt|178 it "honors the #{feature_path_opt} option" do179 config = Spinach::Config.new180 Spinach.stubs(:config).returns(config)181 cli = Spinach::Cli.new([feature_path_opt,"custom_path", generate_opt])182 cli.options183 config.features_path.must_equal 'custom_path'184 end185 end186 end187 end188 describe 'fail-fast' do189 it 'set the fail_fast flag, given "--fail-fast"' do190 config = Spinach::Config.new191 Spinach.stubs(:config).returns(config)192 Spinach::Cli.new(["--fail-fast"]).options193 config.fail_fast.must_equal true194 end195 end196 describe "version" do197 %w{-v --version}.each do |opt|198 it "outputs the version" do199 cli = Spinach::Cli.new([opt])200 cli.expects(:exit)201 cli.expects(:puts).with(Spinach::VERSION)202 capture_stdout do203 cli.options204 end205 end206 end207 end208 describe 'config_path' do209 %w{-c --config_path}.each do |opt|210 it "sets the config path" do211 config = Spinach::Config.new212 Spinach.stubs(:config).returns(config)213 cli = Spinach::Cli.new([opt, 'config_file'])214 config.expects(:parse_from_file)215 cli.options216 config.config_path.must_equal 'config_file'217 end218 it "gets overriden by the other cli options" do219 config = Spinach::Config.new220 Spinach.stubs(:config).returns(config)221 YAML.stubs(:load_file).returns({features_path: 'my_path'})222 cli = Spinach::Cli.new(['-f', 'another_path', opt, 'config_file'])223 cli.options224 config.features_path.must_equal 'another_path'225 end226 end227 end228 describe 'undefined option' do229 %w{-lorem --ipsum}.each do |opt|230 it 'exits and outputs error message with #{opt}' do231 cli = Spinach::Cli.new([opt])232 cli.expects(:exit)233 cli.expects(:puts).with("Invalid option: #{opt}")234 cli.options235 end236 end237 end238 end239 describe '#feature_files' do240 describe 'when a particular feature list is passed' do241 describe 'the feature really exists' do242 it 'runs the feature' do243 cli = Spinach::Cli.new(['features/some_feature.feature'])244 File.stubs(:exists?).returns(true)245 cli.feature_files.must_equal ['features/some_feature.feature']246 end247 end248 it 'it fails if the feature does not exist' do249 cli = Spinach::Cli.new(['features/some_feature.feature'])250 File.stubs(:exists?).returns(false)251 cli.expects(:fail!).with('features/some_feature.feature could not be found')252 cli.feature_files253 end254 end255 describe 'when a particular feature list is passed with line' do256 it 'returns the feature with the line number' do257 cli = Spinach::Cli.new(['features/some_feature.feature:10'])258 File.stubs(:exists?).returns(true)259 cli.feature_files.must_equal ['features/some_feature.feature:10']260 end261 end262 describe "when a particular feature list is passed with multiple lines" do263 it "returns the feature with the line numbers" do264 cli = Spinach::Cli.new(['features/some_feature.feature:10:20'])265 File.stubs(:exists?).returns(true)266 cli.feature_files.must_equal ["features/some_feature.feature:10:20"]267 end268 end269 describe 'when no feature is passed' do270 it 'returns all the features' do271 cli = Spinach::Cli.new([])272 Dir.expects(:glob).with('features/**/*.feature')273 cli.feature_files274 end275 end276 describe 'when a folder is given' do277 it 'returns all feature files in the folder and subfolders' do278 cli = Spinach::Cli.new(['path/to/features'])279 File.stubs(:directory?).returns(true)280 Dir.expects(:glob).with('path/to/features/**/*.feature')281 cli.feature_files282 end283 end284 describe 'when multiple arguments are passed in' do285 describe 'a folder followed by file' do286 it 'returns the features in the folder and the particular file' do287 cli = Spinach::Cli.new(['path/to/features', 'some_feature.feature'])288 File.stubs(:directory?).returns(true)289 Dir.expects(:glob).with('path/to/features/**/*.feature')290 .returns(['several features'])291 File.stubs(:exists?).returns(true)292 cli.feature_files.must_equal ['several features', 'some_feature.feature']293 end294 end295 end296 end297end...
cli.rb
Source:cli.rb
...19 # @api public20 def run21 options22 if Spinach.config.generate23 Spinach::Generators.run(feature_files)24 elsif Spinach.config.audit25 Spinach::Auditor.new(feature_files).run26 else27 Spinach::Runner.new(feature_files).run28 end29 end30 # @return [Hash]31 # A hash of options separated by its type.32 #33 # @example34 # Cli.new.options35 # # => { reporter: { backtrace: true } }36 #37 # @api public38 def options39 @options ||= parse_options40 end41 # Uses given args to list the feature files to run. It will find a single42 # feature, features in a folder and subfolders or every feature file in the43 # feature path.44 #45 # @return [Array]46 # An array with the feature file names.47 #48 # @api public49 def feature_files50 files_to_run = []51 @args.each do |arg|52 if arg.match(/\.feature/)53 if File.exists? arg.gsub(/:\d*/, '')54 files_to_run << arg55 else56 fail! "#{arg} could not be found"57 end58 elsif File.directory?(arg)59 files_to_run << Dir.glob(File.join(arg, '**', '*.feature'))60 elsif arg != "{}"61 fail! "invalid argument - #{arg}"62 end63 end...
feature_files
Using AI Code Generation
1 feature = Spinach.feature(feature_file)2 scenario = Spinach.scenario(scenario)3 step = Spinach.step(step)
feature_files
Using AI Code Generation
1 feature = Spinach.feature(feature_file)2 scenario = Spinach.scenario(scenario)3 step = Spinach.step(step)
feature_files
Using AI Code Generation
1 feature = Spinach.feature(feature_file)2 scenario = Spinach.scenario(scenario)3 step = Spinach.step(step)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!