Best Spinach_ruby code snippet using Spinach.support_path
runner_test.rb
Source:runner_test.rb
...16 )17 runner.step_definitions_path.must_equal 'spinach/step_definitions'18 end19 end20 describe 'support_path' do21 it 'sets a default' do22 runner.support_path.must_be_kind_of String23 end24 it 'can be overriden' do25 runner = Spinach::Runner.new(26 @filename, support_path: 'spinach/environment'27 )28 runner.support_path.must_equal 'spinach/environment'29 end30 end31 end32 describe '#init_reporters' do33 describe "when no reporter_classes option is passed in" do34 it 'inits the default reporter' do35 reporter = stub36 reporter.expects(:bind)37 Spinach::Reporter::Stdout.stubs(new: reporter)38 runner.init_reporters39 end40 end41 describe "when reporter_classes option is passed in" do42 it "inits the reporter classes" do43 config = Spinach::Config.new44 Spinach.stubs(:config).returns(config)45 config.reporter_classes = ["String"]46 reporter = stub47 reporter.expects(:bind)48 String.stubs(new: reporter)49 runner.init_reporters50 end51 end52 describe "when backtrace is passed in" do53 it "inits with backtrace" do54 config = Spinach::Config.new55 Spinach.stubs(:config).returns(config)56 config.reporter_options = {backtrace: true}57 reporter = stub58 reporter.stubs(:bind)59 Spinach::Reporter::Stdout.expects(new: reporter).with(60 backtrace: true,61 **runner.default_reporter_options62 )63 runner.init_reporters64 end65 end66 end67 describe '#run' do68 before(:each) do69 @feature_runner = stub70 filenames.each do |filename|71 Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub72 parser.stubs(:parse).returns feature = Spinach::Feature.new73 Spinach::Runner::FeatureRunner.stubs(:new).74 with(feature, anything).75 returns(@feature_runner)76 end77 @feature_runner.stubs(:run).returns(true)78 runner.stubs(required_files: [])79 end80 it "inits reporters" do81 runner.expects(:init_reporters)82 runner.run83 end84 it 'instantiates a new Feature and runs it with every file' do85 @feature_runner.stubs(:run).returns(true)86 runner.run.must_equal true87 end88 it 'returns false if it fails' do89 @feature_runner.stubs(:run).returns(false)90 runner.run.must_equal false91 end92 describe 'when line set' do93 let(:filename) { 'features/cool_feature.feature' }94 let(:line) { 12 }95 let(:filenames) { ["#{filename}:#{line}"] }96 let(:runner) { Spinach::Runner.new(filenames) }97 it 'sets filename and lines_to_run on the feature' do98 @feature_runner = stub99 Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub100 parser.stubs(:parse).returns feature = Spinach::Feature.new101 Spinach::Runner::FeatureRunner.stubs(:new).102 with(feature, anything).103 returns(@feature_runner)104 runner.stubs(required_files: [])105 @feature_runner.stubs(:run).returns(true)106 runner.run.must_equal true107 feature.filename.must_equal filename108 feature.lines_to_run.must_equal [line]109 end110 end111 describe "when lines set" do112 let(:filename) { "features/cool_feature.feature" }113 let(:line) { "12:24" }114 let(:filenames) { ["#{filename}:#{line}"] }115 let(:runner) { Spinach::Runner.new(filenames) }116 before(:each) do117 @feature_runner = stub118 Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub119 parser.stubs(:parse).returns @feature = Spinach::Feature.new120 Spinach::Runner::FeatureRunner.stubs(:new).121 with(@feature, anything).122 returns(@feature_runner)123 runner.stubs(required_files: [])124 end125 it "sets filename and lines_to_run on the feature" do126 @feature_runner.stubs(:run).returns(true)127 runner.run.must_equal true128 @feature.filename.must_equal filename129 @feature.lines_to_run.must_equal line.split(":").map(&:to_i)130 end131 it "returns false if it fails" do132 @feature_runner.stubs(:run).returns(false)133 runner.run.must_equal false134 end135 it "breaks with a failure when fail fast set" do136 Spinach.config.stubs(:fail_fast).returns true137 @feature_runner.stubs(:run).returns(false)138 @feature_runner.expects(:run).never139 runner.run.must_equal false140 end141 it "does not break when success when fail fast set" do142 Spinach.config.stubs(:fail_fast).returns true143 @feature_runner.stubs(:run).returns(true)144 @feature_runner.expects(:run).returns true145 runner.run.must_equal true146 end147 end148 describe "when fail_fast set" do149 let(:feature_runners) { [ stub, stub ] }150 before(:each) do151 filenames.each_with_index do |filename, i|152 Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub153 parser.stubs(:parse).returns feature = Spinach::Feature.new154 Spinach::Runner::FeatureRunner.stubs(:new).155 with(feature, anything).156 returns(feature_runners[i])157 end158 feature_runners[0].stubs(:run).returns(false)159 runner.stubs(required_files: [])160 Spinach.config.stubs(:fail_fast).returns true161 end162 it "breaks with a failure" do163 feature_runners[1].expects(:run).never164 runner.run.must_equal false165 end166 it "doesn't break when success" do167 feature_runners[0].stubs(:run).returns(true)168 feature_runners[1].expects(:run).returns true169 runner.run.must_equal true170 end171 end172 end173 describe '#require_dependencies' do174 it 'requires support files and step definitions' do175 runner.stubs(176 required_files: ['a', 'b']177 )178 %w{a b}.each do |file|179 runner.expects(:require).with(file)180 end181 runner.require_dependencies182 end183 end184 describe '#required_files' do185 it 'requires the most deeply nested files first, then alphabetically' do186 FakeFS do187 FileUtils.mkdir_p('features/steps/a')188 FileUtils.mkdir_p('features/steps/z')189 ['features/steps/a.rb', 'features/steps/a/a.rb', 'features/steps/z.rb', 'features/steps/z/z.rb'].each do |f|190 FileUtils.touch(f)191 end192 runner.required_files.must_equal(['/features/steps/a/a.rb', '/features/steps/z/z.rb', '/features/steps/a.rb', '/features/steps/z.rb'])193 end194 end195 it 'requires environment files first' do196 runner.stubs(:step_definition_path).returns('steps')197 runner.stubs(:support_path).returns('support')198 Dir.stubs(:glob).returns(['/support/bar.rb', '/support/env.rb', '/support/quz.rb'])199 runner.stubs(:step_definition_files).returns(['/steps/bar.rb'])200 runner.required_files.must_equal(['/support/env.rb', '/support/bar.rb', '/support/quz.rb', '/steps/bar.rb'])201 end202 end203end...
runner.rb
Source:runner.rb
...7 attr_reader :filenames8 # The default path where the steps are located9 attr_reader :step_definitions_path10 # The default path where the support files are located11 attr_reader :support_path12 # Initializes the runner with a parsed feature13 #14 # @param [Array<String>] filenames15 # A list of feature filenames to run16 #17 # @param [Hash] options18 #19 # @option options [String] :step_definitions_path20 # The path in which step definitions are found.21 #22 # @option options [String] :support_path23 # The path with the support ruby files.24 #25 # @api public26 def initialize(filenames, options = {})27 @filenames = filenames28 @step_definitions_path = options.delete(:step_definitions_path) ||29 Spinach.config.step_definitions_path30 @support_path = options.delete(:support_path) ||31 Spinach.config.support_path32 end33 # Inits the reporter with a default one.34 #35 # @api public36 def init_reporters37 Spinach.config[:reporter_classes].each do |reporter_class|38 reporter_options = default_reporter_options.merge(Spinach.config.reporter_options)39 reporter = Support.constantize(reporter_class).new(reporter_options)40 reporter.bind41 end42 end43 # Runs this runner and outputs the results in a colorful manner.44 #45 # @return [true, false]46 # Whether the run was succesful.47 #48 # @api public49 def run50 require_dependencies51 require_frameworks52 init_reporters53 suite_passed = true54 Spinach.hooks.run_before_run55 features_to_run.each do |feature|56 feature_passed = FeatureRunner.new(feature, orderer: orderer).run57 suite_passed &&= feature_passed58 break if fail_fast? && !feature_passed59 end60 Spinach.hooks.run_after_run(suite_passed)61 suite_passed62 end63 # Loads support files and step definitions, ensuring that env.rb is loaded64 # first.65 #66 # @api public67 def require_dependencies68 required_files.each do |file|69 require file70 end71 end72 # Requires the test framework support73 #74 def require_frameworks75 require_relative 'frameworks'76 end77 # Returns an array of files to be required. Sorted by the most nested files first, then alphabetically.78 # @return [Array<String>] files79 # The step definition files.80 #81 # @api public82 def step_definition_files83 Dir.glob(84 File.expand_path File.join(step_definitions_path, '**', '*.rb')85 ).sort{|a,b| [b.count(File::SEPARATOR), a] <=> [a.count(File::SEPARATOR), b]}86 end87 # Returns an array of support files inside the support_path. Will88 # put "env.rb" in the beginning89 #90 # @return [Array<String>] files91 # The support files.92 #93 # @api public94 def support_files95 support_files = Dir.glob(96 File.expand_path File.join(support_path, '**', '*.rb')97 )98 environment_file = support_files.find do |f|99 f.include?(File.join support_path, 'env.rb')100 end101 support_files.unshift(environment_file).compact.uniq102 end103 # @return [Array<String>] files104 # All support files with env.rb ordered first, followed by the step105 # definitions.106 #107 # @api public108 def required_files109 support_files + step_definition_files110 end111 # The orderer for this run.112 #113 # @api public...
config_test.rb
Source:config_test.rb
...47 subject[:step_definitions_path] = 'steps'48 subject[:step_definitions_path].must_equal 'steps'49 end50 end51 describe '#support_path' do52 it 'returns a default' do53 subject[:support_path].must_be_kind_of String54 end55 it 'can be overwritten' do56 subject[:support_path] = 'support'57 subject[:support_path].must_equal 'support'58 end59 end60 describe '#failure_exceptions' do61 it 'returns a default' do62 subject[:failure_exceptions].must_be_kind_of Array63 end64 it 'can be overwritten' do65 subject[:failure_exceptions] = [1, 2, 3]66 subject[:failure_exceptions].must_equal [1,2,3]67 end68 it 'allows adding elements' do69 subject[:failure_exceptions] << RuntimeError70 subject[:failure_exceptions].must_include RuntimeError71 end72 end73 describe '#config_path' do74 it 'returns a default' do75 subject[:config_path].must_equal 'config/spinach.yml'76 end77 it 'can be overwritten' do78 subject[:config_path] = 'my_config_file.yml'79 subject[:config_path].must_equal 'my_config_file.yml'80 end81 end82 describe '#parse_from_file' do83 before do84 subject[:config_path] = 'a_path'85 YAML.stubs(:load_file).returns({support_path: 'my_path', config_path: 'another_path'})86 subject.parse_from_file87 end88 it 'sets the options' do89 subject[:support_path].must_equal 'my_path'90 end91 it "doesn't set the config_path option" do92 subject[:config_path].must_equal 'a_path'93 end94 end95 describe '#tags' do96 it 'returns a default' do97 subject[:tags].must_be_kind_of Array98 end99 it 'can be overwritten' do100 subject[:tags] = ['wip']101 subject[:tags].must_equal ['wip']102 end103 end...
support_path
Using AI Code Generation
1Spinach.hooks.on_tag("foo") do2Spinach.hooks.on_tag("bar") do3Spinach.hooks.on_tag("baz") do4Spinach.hooks.on_tag("qux") do5Spinach.hooks.on_tag("quux") do6Spinach.hooks.on_tag("corge") do7Spinach.hooks.on_tag("grault") do8Spinach.hooks.on_tag("garply") do9Spinach.hooks.on_tag("waldo") do10Spinach.hooks.on_tag("fred") do11Spinach.hooks.on_tag("plugh") do12Spinach.hooks.on_tag("xyzzy") do13Spinach.hooks.on_tag("thud") do
support_path
Using AI Code Generation
1Dir[Spinach.support_path.join('**/*.rb')].each do |file|2Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|3Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|4Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|5Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|6Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|7Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|8Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|9Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|10Dir[Spinach::Support::Path.support_path.join('**/*.rb')].each do |file|
support_path
Using AI Code Generation
1Spinach.hooks.on_tag('require_support_files') do2 Spinach.support_path.glob('*.rb').each { |f| require f }3Spinach.hooks.on_tag('require_support_files') do4 Spinach.config[:features_path].glob('**/steps/*.rb').each { |f| require f }5Spinach.hooks.on_tag('require_support_files') do6 Spinach.config[:features_path].glob('**/steps/*.rb').each { |f| require f }7Spinach.hooks.on_tag('require_support_files') do8 Spinach.config[:features_path].glob('**/steps/*.rb').each { |f| require f }9Spinach.hooks.on_tag('require_support_files') do10 Spinach.config[:features_path].glob('**/steps/*.rb').each { |f| require f }11Spinach.hooks.on_tag('require_support_files') do
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!!