Class: AnySpec::TestCase
- Inherits:
-
Object
- Object
- AnySpec::TestCase
- Defined in:
- lib/any-spec/test-case.rb
Instance Attribute Summary collapse
-
#assertion_code ⇒ Object
Returns the value of attribute assertion_code.
-
#assertions ⇒ Object
Returns the value of attribute assertions.
-
#exit_status ⇒ Object
Returns the value of attribute exit_status.
-
#last_assertion_result ⇒ Object
Returns the value of attribute last_assertion_result.
-
#message ⇒ Object
Returns the value of attribute message.
-
#path ⇒ Object
Returns the value of attribute path.
-
#target_executable ⇒ Object
Returns the value of attribute target_executable.
-
#test_code ⇒ Object
Returns the value of attribute test_code.
-
#test_output ⇒ Object
Returns the value of attribute test_output.
Instance Method Summary collapse
-
#initialize(path, target_executable) ⇒ TestCase
constructor
A new instance of TestCase.
- #run ⇒ Object
Constructor Details
#initialize(path, target_executable) ⇒ TestCase
Returns a new instance of TestCase.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/any-spec/test-case.rb', line 14 def initialize(path, target_executable) raise Exception, "\n\nNo test case exists at path: #{path}" unless(File.exist?(path)) raise Exception, "\n\nTest case is empty: #{path}" if(File.size(path) == 0) raw_test = File.open(path).read test_parts = raw_test.split("----") raise Exception, "\n\nTest case formatted incorrectly: #{path}" unless(test_parts.length == 2) @test_code = test_parts[0].strip @assertion_code = test_parts[1].strip @path = path @target_executable = target_executable end |
Instance Attribute Details
#assertion_code ⇒ Object
Returns the value of attribute assertion_code.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def assertion_code @assertion_code end |
#assertions ⇒ Object
Returns the value of attribute assertions.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def assertions @assertions end |
#exit_status ⇒ Object
Returns the value of attribute exit_status.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def exit_status @exit_status end |
#last_assertion_result ⇒ Object
Returns the value of attribute last_assertion_result.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def last_assertion_result @last_assertion_result end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def @message end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def path @path end |
#target_executable ⇒ Object
Returns the value of attribute target_executable.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def target_executable @target_executable end |
#test_code ⇒ Object
Returns the value of attribute test_code.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def test_code @test_code end |
#test_output ⇒ Object
Returns the value of attribute test_output.
4 5 6 |
# File 'lib/any-spec/test-case.rb', line 4 def test_output @test_output end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/any-spec/test-case.rb', line 26 def run temporary_filename = File.join( File.split(@path)[0], "#{Time.now.to_i}-any-spec" + File.extname(@path) ) tmp = File.open(temporary_filename, "w") tmp.write(@test_code) tmp.close @test_output = `#{@target_executable} #{temporary_filename} 2>&1` @exit_status = $?.exitstatus @last_assertion_result = true @message = "" @assertions = 0 unless(@assertion_code.include?("assert_execution_success") || @assertion_code.include?("assert_execution_failure")) @assertion_code = "\nassert_execution_success\n" + @assertion_code end begin AnySpec::Assertions.new(self).instance_eval(@assertion_code, @path) rescue Exception => e @message = "Error in assertion code:\n" @message += e. @message += "\n" + e.backtrace.join("\n") @last_assertion_result = false end return @last_assertion_result ensure File.delete(temporary_filename) end |