Class: Assert::Test
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
a Test is some code/method to run in the scope of a Context.
-
#context_info ⇒ Object
readonly
a Test is some code/method to run in the scope of a Context.
-
#name ⇒ Object
readonly
a Test is some code/method to run in the scope of a Context.
-
#output ⇒ Object
Returns the value of attribute output.
-
#results ⇒ Object
Returns the value of attribute results.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other_test) ⇒ Object
- #context_class ⇒ Object
-
#initialize(name, suite_context_info, code = nil, &block) ⇒ Test
constructor
A new instance of Test.
- #inspect ⇒ Object
- #result_count(type = nil) ⇒ Object
- #run(view = nil) ⇒ Object
Methods included from Options
Constructor Details
#initialize(name, suite_context_info, code = nil, &block) ⇒ Test
Returns a new instance of Test.
25 26 27 28 29 30 31 |
# File 'lib/assert/test.rb', line 25 def initialize(name, suite_context_info, code = nil, &block) @context_info = suite_context_info @name = name_from_context(name) @code = (code || block) @results = ResultSet.new @output = "" end |
Instance Attribute Details
#code ⇒ Object (readonly)
a Test is some code/method to run in the scope of a Context. After a a test runs, it should have some assertions which are its results.
22 23 24 |
# File 'lib/assert/test.rb', line 22 def code @code end |
#context_info ⇒ Object (readonly)
a Test is some code/method to run in the scope of a Context. After a a test runs, it should have some assertions which are its results.
22 23 24 |
# File 'lib/assert/test.rb', line 22 def context_info @context_info end |
#name ⇒ Object (readonly)
a Test is some code/method to run in the scope of a Context. After a a test runs, it should have some assertions which are its results.
22 23 24 |
# File 'lib/assert/test.rb', line 22 def name @name end |
#output ⇒ Object
Returns the value of attribute output.
23 24 25 |
# File 'lib/assert/test.rb', line 23 def output @output end |
#results ⇒ Object
Returns the value of attribute results.
23 24 25 |
# File 'lib/assert/test.rb', line 23 def results @results end |
Class Method Details
.halt_on_fail? ⇒ Boolean
15 16 17 |
# File 'lib/assert/test.rb', line 15 def self.halt_on_fail? ENV['halt_on_fail'] == 'true' || self..halt_on_fail end |
Instance Method Details
#<=>(other_test) ⇒ Object
92 93 94 |
# File 'lib/assert/test.rb', line 92 def <=>(other_test) self.name <=> other_test.name end |
#context_class ⇒ Object
33 34 35 |
# File 'lib/assert/test.rb', line 33 def context_class self.context_info.klass end |
#inspect ⇒ Object
96 97 98 99 100 101 |
# File 'lib/assert/test.rb', line 96 def inspect attributes_string = ([ :name, :context_info, :results ].collect do |attr| "@#{attr}=#{self.send(attr).inspect}" end).join(" ") "#<#{self.class} #{attributes_string}>" end |
#result_count(type = nil) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/assert/test.rb', line 84 def result_count(type=nil) if Assert::Result.types.include?(type) self.send("#{type}_results").size else @results.size end end |
#run(view = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/assert/test.rb', line 37 def run(view=nil) @results.view = view run_scope = self.context_class.new(self) capture_output(StringIO.new(@output, "w+")) do begin # run any assert style 'setup do' setups self.context_class.setup(run_scope) # run any classic test/unit style 'def setup' setups if run_scope.respond_to?(:setup) run_scope.setup end # run the actual test code if @code.kind_of?(::Proc) run_scope.instance_eval(&@code) elsif run_scope.respond_to?(@code.to_s) run_scope.send(@code.to_s) end rescue Result::TestFailure => err @results << Result::Fail.new(self, err) rescue Result::TestSkipped => err @results << Result::Skip.new(self, err) rescue Exception => err @results << Result::Error.new(self, err) ensure begin # run any classic test/unit style 'def teardown' teardowns if run_scope.respond_to?(:teardown) run_scope.teardown end # run any assert style 'teardown do' teardowns self.context_class.teardown(run_scope) rescue Exception => teardown_err @results << Result::Error.new(self, teardown_err) end end end @results.view = nil @results end |