How to use current_appraisal method of Tests Package

Best Shoulda_ruby code snippet using Tests.current_appraisal

test_framework_detection_test.rb

Source: test_framework_detection_test.rb Github

copy

Full Screen

1require "test_helper"2require "tempfile"3class TestFrameworkDetectionTest < PARENT_TEST_CASE4 if Tests::CurrentBundle.instance.current_appraisal == "rails_5_2"5 should "detect Minitest 5.x w/​ Rails 5.2" do6 assert_integration_with_rails_and "Minitest::Test"7 end8 end9 if Tests::CurrentBundle.instance.current_appraisal == "rails_5_1"10 should "detect Minitest 5.x w/​ Rails 5.1" do11 assert_integration_with_rails_and "Minitest::Test"12 end13 end14 if Tests::CurrentBundle.instance.current_appraisal == "rails_5_0"15 should "detect Minitest 5.x w/​ Rails 5.0" do16 assert_integration_with_rails_and "Minitest::Test"17 end18 end19 if Tests::CurrentBundle.instance.current_appraisal == "rails_4_2"20 should "detect ActiveSupport::TestCase and Minitest 4.x w/​ Rails 4.2" do21 assert_integration_with_rails_and "Minitest::Test"22 end23 end24 if TEST_FRAMEWORK == "minitest"25 should "detect Minitest 5.x when it is loaded standalone" do26 assert_integration_with "Minitest::Test", setup: <<-RUBY27 require "minitest/​autorun"28 RUBY29 end30 end31 if TEST_FRAMEWORK == "test_unit"32 should "detect the test-unit gem when it is loaded standalone" do33 assert_integration_with "Test::Unit::TestCase",34 setup: <<-RUBY35 require "test/​unit"36 RUBY37 end38 end39 def assert_integration_with_rails_and(*test_cases)40 test_cases = ["ActiveSupport::TestCase"] | test_cases41 options = test_cases.last.is_a?(Hash) ? test_cases.pop : {}42 options[:setup] = <<-RUBY43 require "rails/​all"44 require "rails/​test_help"45 ActiveRecord::Base.establish_connection(46 adapter: "sqlite3",47 database: ":memory:"48 )49 RUBY50 args = test_cases + [options]51 assert_integration_with(*args)52 end53 def assert_integration_with(*test_cases)54 assert_test_cases_are_detected(*test_cases)55 assert_our_api_is_available_in_test_cases(*test_cases)56 end57 def assert_test_cases_are_detected(*expected_test_cases)58 options = expected_test_cases.last.is_a?(Hash) ? expected_test_cases.pop : {}59 setup = options[:setup] || ""60 output = execute(file_that_detects_test_framework_test_cases([setup]))61 actual_test_cases = output.split("\n").first.split(", ")62 assert_equal expected_test_cases, actual_test_cases63 end64 def file_that_detects_test_framework_test_cases(mixins)65 <<-RUBY66 #{require_gems(mixins)}67 require "yaml"68 test_cases =69 Shoulda::Context.test_framework_test_cases.map do |test_case|70 test_case.to_s71 end72 puts test_cases.join(', ')73 RUBY74 end75 def require_gems(mixins)76 <<-RUBY77 ENV["BUNDLE_GEMFILE"] =78 "#{PROJECT_DIR}/​gemfiles/​" +79 "#{Tests::CurrentBundle.instance.current_appraisal}.gemfile"80 require "bundler"81 Bundler.setup82 #{mixins.join("\n")}83 require "shoulda-context"84 RUBY85 end86 def assert_our_api_is_available_in_test_cases(*test_cases)87 options = test_cases.last.is_a?(Hash) ? test_cases.pop : {}88 setup = options[:setup] || ""89 test_cases.each do |test_case|90 output = execute(91 file_that_runs_a_test_within_test_case(test_case, [setup])92 )93 assert_match(/​1 (tests|runs)/​, output)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why does DevOps recommend shift-left testing principles?

Companies are using DevOps to quickly respond to changing market dynamics and customer requirements.

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

Getting Rid of Technical Debt in Agile Projects

Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.

Complete Guide To Styling Forms With CSS Accent Color

The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).

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:

YouTube

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?

Helpful

NotHelpful