Class: Sapphire::Testing::RakeTask
- Defined in:
- lib/sapphire/Testing/RakeTask.rb
Instance Attribute Summary collapse
-
#fail_on_error ⇒ Object
Returns the value of attribute fail_on_error.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(*args) {|_self| ... } ⇒ RakeTask
constructor
A new instance of RakeTask.
- #test_outcome(result) ⇒ Object
Constructor Details
#initialize(*args) {|_self| ... } ⇒ RakeTask
Returns a new instance of RakeTask.
35 36 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sapphire/Testing/RakeTask.rb', line 35 def initialize(*args) @name = args.shift || :spec @pattern = nil @verbose, @fail_on_error = true, true yield self if block_given? Rake::Task.define_task name do RakeFileUtils.send(:verbose, verbose) do files_to_run = FileList[ pattern ].map { |f| y = nil x = nil x = f.gsub(/"/, '\"') if f != nil y = x.gsub(/'/, "\\\\'") if x != nil y } if files_to_run.empty? puts "No examples matching #{pattern} could be found" else begin files_to_run.each do |f| next unless f != nil require File.("../../" + f.to_s, __FILE__) unless File.directory? f end success_array = [] pending_array = [] failure_array = [] i = 3 Runner.instance.scenarios.each do |scenario| i += 1 scenario.execute i scenario.result.set_id i scenario.result.set_type test_outcome(scenario.result) success_array << scenario.result if scenario.result.type == "pass" pending_array << scenario.result if scenario.result.type == "pending" failure_array << scenario.result if scenario.result.type == "fail" end item_array = [] item_array << ResultsList.new("Passing", success_array, 1) item_array << ResultsList.new("Pending", pending_array, 2) item_array << ResultsList.new("Failing", failure_array, 3) File.open(File.dirname(__FILE__) + "/../ReportGenerator/output.json", "w") do |file| file.puts ActiveSupport::JSON.encode item_array end Runner.instance.scenarios.each do |scenario| File.open(File.dirname(__FILE__) + "/../ReportGenerator/" + scenario.result.myId.to_s + ".json", "w") do |file| file.puts ActiveSupport::JSON.encode scenario.result end end rescue => e stack = "" e.backtrace.each do |line| stack += "\r\n" + line end raise("Some tests have failed: " + e. + " : " + stack) if fail_on_error end end end end end |
Instance Attribute Details
#fail_on_error ⇒ Object
Returns the value of attribute fail_on_error.
9 10 11 |
# File 'lib/sapphire/Testing/RakeTask.rb', line 9 def fail_on_error @fail_on_error end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/sapphire/Testing/RakeTask.rb', line 10 def name @name end |
#pattern ⇒ Object
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/sapphire/Testing/RakeTask.rb', line 7 def pattern @pattern end |
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/sapphire/Testing/RakeTask.rb', line 8 def verbose @verbose end |
Instance Method Details
#test_outcome(result) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sapphire/Testing/RakeTask.rb', line 13 def test_outcome(result) result.results.each do |r| if(r.type == 'fail') return 'fail' end if(r.type == 'pending') return 'pending' end if(!r.results.empty?) return test_outcome(r) end end return 'pass' end |