How to use nodoc method of Minitest Package

Best Minitest_ruby code snippet using Minitest.nodoc

spec.rb

Source:spec.rb Github

copy

Full Screen

1require "minitest/test"2class Module # :nodoc:3 def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:4 # warn "%-22p -> %p %p" % [meth, new_name, dont_flip]5 self.class_eval <<-EOM6 def #{new_name} *args7 Minitest::Expectation.new(self, Minitest::Spec.current).#{new_name}(*args)8 end9 EOM10 Minitest::Expectation.class_eval <<-EOM, __FILE__, __LINE__ + 111 def #{new_name} *args12 case13 when #{!!dont_flip} then14 ctx.#{meth}(target, *args)15 when Proc === target then16 ctx.#{meth}(*args, &target)17 else18 ctx.#{meth}(args.first, target, *args[1..-1])19 end20 end21 EOM22 end23end24Minitest::Expectation = Struct.new :target, :ctx # :nodoc:25##26# Kernel extensions for minitest27module Kernel28 ##29 # Describe a series of expectations for a given target +desc+.30 #31 # Defines a test class subclassing from either Minitest::Spec or32 # from the surrounding describe's class. The surrounding class may33 # subclass Minitest::Spec manually in order to easily share code:34 #35 # class MySpec < Minitest::Spec36 # # ... shared code ...37 # end38 #39 # class TestStuff < MySpec40 # it "does stuff" do41 # # shared code available here42 # end43 # describe "inner stuff" do44 # it "still does stuff" do45 # # ...and here46 # end47 # end48 # end49 #50 # For more information on getting started with writing specs, see:51 #52 # http://www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html53 #54 # For some suggestions on how to improve your specs, try:55 #56 # http://betterspecs.org57 #58 # but do note that several items there are debatable or specific to59 # rspec.60 #61 # For more information about expectations, see Minitest::Expectations.62 def describe desc, *additional_desc, &block # :doc:63 stack = Minitest::Spec.describe_stack64 name = [stack.last, desc, *additional_desc].compact.join("::")65 sclas = stack.last || if Class === self && kind_of?(Minitest::Spec::DSL) then66 self67 else68 Minitest::Spec.spec_type desc, *additional_desc69 end70 cls = sclas.create name, desc71 stack.push cls72 cls.class_eval(&block)73 stack.pop74 cls75 end76 private :describe77end78##79# Minitest::Spec -- The faster, better, less-magical spec framework!80#81# For a list of expectations, see Minitest::Expectations.82class Minitest::Spec < Minitest::Test83 def self.current # :nodoc:84 Thread.current[:current_spec]85 end86 def initialize name # :nodoc:87 super88 Thread.current[:current_spec] = self89 end90 ##91 # Oh look! A Minitest::Spec::DSL module! Eat your heart out DHH.92 module DSL93 ##94 # Contains pairs of matchers and Spec classes to be used to95 # calculate the superclass of a top-level describe. This allows for96 # automatically customizable spec types.97 #98 # See: register_spec_type and spec_type99 TYPES = [[//, Minitest::Spec]]100 ##101 # Register a new type of spec that matches the spec's description.102 # This method can take either a Regexp and a spec class or a spec103 # class and a block that takes the description and returns true if104 # it matches.105 #106 # Eg:107 #108 # register_spec_type(/Controller$/, Minitest::Spec::Rails)109 #110 # or:111 #112 # register_spec_type(Minitest::Spec::RailsModel) do |desc|113 # desc.superclass == ActiveRecord::Base114 # end115 def register_spec_type(*args, &block)116 if block then117 matcher, klass = block, args.first118 else119 matcher, klass = *args120 end121 TYPES.unshift [matcher, klass]122 end123 ##124 # Figure out the spec class to use based on a spec's description. Eg:125 #126 # spec_type("BlahController") # => Minitest::Spec::Rails127 def spec_type desc, *additional128 TYPES.find { |matcher, _klass|129 if matcher.respond_to? :call then130 matcher.call desc, *additional131 else132 matcher === desc.to_s133 end134 }.last135 end136 def describe_stack # :nodoc:137 Thread.current[:describe_stack] ||= []138 end139 def children # :nodoc:140 @children ||= []141 end142 def nuke_test_methods! # :nodoc:143 self.public_instance_methods.grep(/^test_/).each do |name|144 self.send :undef_method, name145 end146 end147 ##148 # Define a 'before' action. Inherits the way normal methods should.149 #150 # NOTE: +type+ is ignored and is only there to make porting easier.151 #152 # Equivalent to Minitest::Test#setup.153 def before _type = nil, &block154 define_method :setup do155 super()156 self.instance_eval(&block)157 end158 end159 ##160 # Define an 'after' action. Inherits the way normal methods should.161 #162 # NOTE: +type+ is ignored and is only there to make porting easier.163 #164 # Equivalent to Minitest::Test#teardown.165 def after _type = nil, &block166 define_method :teardown do167 self.instance_eval(&block)168 super()169 end170 end171 ##172 # Define an expectation with name +desc+. Name gets morphed to a173 # proper test method name. For some freakish reason, people who174 # write specs don't like class inheritance, so this goes way out of175 # its way to make sure that expectations aren't inherited.176 #177 # This is also aliased to #specify and doesn't require a +desc+ arg.178 #179 # Hint: If you _do_ want inheritance, use minitest/test. You can mix180 # and match between assertions and expectations as much as you want.181 def it desc = "anonymous", &block182 block ||= proc { skip "(no tests defined)" }183 @specs ||= 0184 @specs += 1185 name = "test_%04d_%s" % [ @specs, desc ]186 undef_klasses = self.children.reject { |c| c.public_method_defined? name }187 define_method name, &block188 undef_klasses.each do |undef_klass|189 undef_klass.send :undef_method, name190 end191 name192 end193 ##194 # Essentially, define an accessor for +name+ with +block+.195 #196 # Why use let instead of def? I honestly don't know.197 def let name, &block198 name = name.to_s199 pre, post = "let '#{name}' cannot ", ". Please use another name."200 methods = Minitest::Spec.instance_methods.map(&:to_s) - %w[subject]201 raise ArgumentError, "#{pre}begin with 'test'#{post}" if202 name =~ /\Atest/203 raise ArgumentError, "#{pre}override a method in Minitest::Spec#{post}" if204 methods.include? name205 define_method name do206 @_memoized ||= {}207 @_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }208 end209 end210 ##211 # Another lazy man's accessor generator. Made even more lazy by212 # setting the name for you to +subject+.213 def subject &block214 let :subject, &block215 end216 def create name, desc # :nodoc:217 cls = Class.new(self) do218 @name = name219 @desc = desc220 nuke_test_methods!221 end222 children << cls223 cls224 end225 def name # :nodoc:226 defined?(@name) ? @name : super227 end228 def to_s # :nodoc:229 name # Can't alias due to 1.8.7, not sure why230 end231 attr_reader :desc # :nodoc:232 alias :specify :it233 module InstanceMethods # :nodoc:234 def before_setup # :nodoc:235 super236 Thread.current[:current_spec] = self237 end238 end239 def self.extended obj # :nodoc:240 obj.send :include, InstanceMethods241 end242 end243 extend DSL244 TYPES = DSL::TYPES # :nodoc:245end246require "minitest/expectations"247class Object # :nodoc:248 include Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]249end...

Full Screen

Full Screen

nodoc

Using AI Code Generation

copy

Full Screen

1ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]2minitest (5.10.1)3rake (12.0.0)4rubygems-bundler (1.4.4)5rubygems-update (2.6.14)6bundler (1.15.4)7rdoc (4.3.0)8yard (0.9.11)9json (2.0.3)10psych (3.0.2)11rake (12.0.0)12rubygems-bundler (1.4.4)13rubygems-update (2.6.14)14bundler (1.15.4)15rdoc (4.3.0)16yard (0.9.11)17json (2.0.3)18psych (3.0.2)19rake (12.0.0)20rubygems-bundler (1.4.4)21rubygems-update (2.6.14)22bundler (1.15.4)23rdoc (4.3.0)24yard (0.9.11)

Full Screen

Full Screen

nodoc

Using AI Code Generation

copy

Full Screen

1ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]2minitest (5.10.1)3rake (12.0.0)4rubygems-bundler (1.4.4)5rubygems-update (2.6.14)6bundler (1.15.4)7rdoc (4.3.0)8yard (0.9.11)9json (2.0.3)10psych (3.0.2)11rake (12.0.0)12rubygems-bundler (1.4.4)13rubygems-update (2.6.14)14bundler (1.15.4)15rdoc (4.3.0)16yard (0.9.11)17json (2.0.3)18psych (3.0.2)19rake (12.0.0)20rubygems-bundler (1.4.4)21rubygems-update (2.6.14)22bundler (1.15.4)23rdoc (4.3.0)24yard (0.9.11)

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:

YouTube

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

Run Minitest_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