How to use path method of Tests Package

Best Shoulda_ruby code snippet using Tests.path


Source:testing.rake Github


Full Screen

1TEST_CHANGES_SINCE = - 6002# Look up tests for recently modified sources.3def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)4 FileList[source_pattern].map do |path|5 if File.mtime(path) > touched_since6 tests = []7 source_dir = File.dirname(path).split("/")8 source_file = File.basename(path, '.rb')9 # Support subdirs in app/models and app/controllers10 modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path11 # For modified files in app/ run the tests for it. ex. /test/functional/account_controller.rb12 test = "#{modified_test_path}/#{source_file}_test.rb"13 tests.push test if File.exist?(test)14 # For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb15 test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}"16 FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test)17 return tests18 end19 end.flatten.compact20end21# Recreated here from ActiveSupport because :uncommitted needs it before Rails is available22module Kernel23 def silence_stderr24 old_stderr = STDERR.dup25 STDERR.reopen(RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'NUL:' : '/dev/null')26 STDERR.sync = true27 yield28 ensure29 STDERR.reopen(old_stderr)30 end31end32desc 'Run all unit, functional and integration tests'33task :test do34 errors = %w(test:units test:functionals test:integration).collect do |task|35 begin36 Rake::Task[task].invoke37 nil38 rescue => e39 task40 end41 end.compact42 abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any?43end44namespace :test do45 => "db:test:prepare") do |t|46 since = TEST_CHANGES_SINCE47 touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +48 recent_tests('app/models/**/*.rb', 'test/unit', since) +49 recent_tests('app/controllers/**/*.rb', 'test/functional', since)50 t.libs << 'test'51 t.verbose = true52 t.test_files = touched.uniq53 end54 Rake::Task['test:recent'].comment = "Test recent changes"55 => "db:test:prepare") do |t|56 def t.file_list57 if".svn")58 changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] }59 elsif".git")60 changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.map { |path| path.chomp }61 else62 abort "Not a Subversion or Git checkout."63 end64 models = { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }65 controllers = { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }66 unit_tests = { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" }67 functional_tests = { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" }68 unit_tests.uniq + functional_tests.uniq69 end70 t.libs << 'test'71 t.verbose = true72 end73 Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)"74 => "db:test:prepare") do |t|75 t.libs << "test"76 t.pattern = 'test/unit/**/*_test.rb'77 t.verbose = true78 end79 Rake::Task['test:units'].comment = "Run the unit tests in test/unit"...

Full Screen

Full Screen


Source:6_validations_spec.rb Github


Full Screen

1require 'spec_helper'2require_relative '../../config/initializers/6_validations.rb'3describe '6_validations', lib: true do4 before :all do5 FileUtils.mkdir_p('tmp/tests/paths/a/b/c/d')6 FileUtils.mkdir_p('tmp/tests/paths/a/b/c2')7 FileUtils.mkdir_p('tmp/tests/paths/a/b/d')8 end9 after :all do10 FileUtils.rm_rf('tmp/tests/paths')11 end12 describe 'validate_storages_config' do13 context 'with correct settings' do14 before do15 mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/d' })16 end17 it 'passes through' do18 expect { validate_storages_config }.not_to raise_error19 end20 end21 context 'with invalid storage names' do22 before do23 mock_storages('name with spaces' => { 'path' => 'tmp/tests/paths/a/b/c' })24 end25 it 'throws an error' do26 expect { validate_storages_config }.to raise_error('"name with spaces" is not a valid storage name. Please fix this in your gitlab.yml before starting GitLab.')27 end28 end29 context 'with incomplete settings' do30 before do31 mock_storages('foo' => {})32 end33 it 'throws an error suggesting the user to update its settings' do34 expect { validate_storages_config }.to raise_error('foo is not a valid storage, because it has no `path` key. Refer to gitlab.yml.example for an updated example. Please fix this in your gitlab.yml before starting GitLab.')35 end36 end37 context 'with deprecated settings structure' do38 before do39 mock_storages('foo' => 'tmp/tests/paths/a/b/c')40 end41 it 'throws an error suggesting the user to update its settings' do42 expect { validate_storages_config }.to raise_error("foo is not a valid storage, because it has no `path` key. It may be configured as:\n\nfoo:\n path: tmp/tests/paths/a/b/c\n\nFor source installations, update your config/gitlab.yml Refer to gitlab.yml.example for an updated example.\n\nIf you're using the Gitlab Development Kit, you can update your configuration running `gdk reconfigure`.\n")43 end44 end45 end46 describe 'validate_storages_paths' do47 context 'with correct settings' do48 before do49 mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/d' })50 end51 it 'passes through' do52 expect { validate_storages_paths }.not_to raise_error53 end54 end55 context 'with nested storage paths' do56 before do57 mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/c/d' })58 end59 it 'throws an error' do60 expect { validate_storages_paths }.to raise_error('bar is a nested path of foo. Nested paths are not supported for repository storages. Please fix this in your gitlab.yml before starting GitLab.')61 end62 end63 context 'with similar but un-nested storage paths' do64 before do65 mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/c2' })66 end67 it 'passes through' do68 expect { validate_storages_paths }.not_to raise_error69 end70 end71 end72 def mock_storages(storages)73 allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)74 end75end...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Shoulda_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?