Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. # using test/spec behave type methods in TestUnit classes
  2. require 'test/spec'
  3. require 'watir/testcase'
  4.  
  5. class TC_me < Watir::TestCase
  6. def test_me
  7. 'bla'.should == 'bla'
  8. puts "TC_me_me"
  9. end
  10. def test_you
  11. 1.should.be 1
  12. puts 'TC_me_you'
  13. end
  14. end
  15.  
  16. class TC_abc < Watir::TestCase
  17. def test_bla
  18. true.should.be true
  19. puts "TC_wow_bla"
  20. end
  21. def test_yay
  22. false.should.be false
  23. puts "TC_wow_yay"
  24. end
  25. end
  26.  
  27. # this will not be picked up by the Spy. that's ok
  28. context 'HelloWorld Context Name' do
  29. it 'the it method' do
  30. true.should.be true
  31. puts 'context_it'
  32. end
  33. it 'some other thing' do
  34. true.should.be true
  35. puts 'context_other'
  36. end
  37. end
  38.  
  39. class TC_wow < Watir::TestCase
  40. def test_bla
  41. true.should.be true
  42. puts "TC_wow_bla"
  43. end
  44. def test_yay
  45. false.should.be false
  46. puts "TC_wow_yay"
  47. end
  48. end
  49.  
  50.  
  51.  
  52. module TestSpaceSpy
  53. class << self
  54. def tests
  55. # finding what tests are loaded in ObjectSpace
  56. tests =[]
  57. ObjectSpace.each_object(Class)do |klass|
  58. if(Test::Unit::TestCase > klass)
  59. tests << klass.suite unless klass == Watir::TestCase
  60. end
  61. end
  62. tests.reverse #TODO I don't know why I need to reverse this to have sequential here
  63. end
  64.  
  65. def to_a
  66. out =[]
  67. tests.each do |test|
  68. rec =[];rec << test.name
  69. srec = [];test.tests.each {|tm| srec << tm.method_name};rec << srec
  70. out << rec
  71. end
  72. out
  73. end
  74.  
  75. def to_yaml
  76. YAML.dump(to_a)
  77. end
  78. end
  79. end
  80.  
  81. # get the yaml representation of all TestCases loaded in ObjectSpace
  82. puts 'Watir TestCases to Run'
  83. p TestSpaceSpy.to_a
  84. puts TestSpaceSpy.to_yaml
  85.  
  86. =begin
  87. [["TC_me", ["test_me", "test_you"]],
  88. ["TC_abc", ["test_bla", "test_yay"]],
  89. ["HelloWorld Context Name", ["test_spec {HelloWorld Context Name} 001 [the it method]", "test_spec {HelloWorld Context Name} 002 [some other thing]"]],
  90. ["TC_wow", ["test_bla", "test_yay"]]]
  91.  
  92. ---
  93. - - TC_me
  94. - - test_me
  95. - test_you
  96. - - TC_abc
  97. - - test_bla
  98. - test_yay
  99. - - HelloWorld Context Name
  100. - - test_spec {HelloWorld Context Name} 001 [the it method]
  101. - test_spec {HelloWorld Context Name} 002 [some other thing]
  102. - - TC_wow
  103. - - test_bla
  104. - test_yay
  105.  
  106. Loaded suite <bla>
  107. Started
  108. TC_wow_bla
  109. TC_wow_yay
  110. TC_wow_bla
  111. TC_wow_yay
  112. TC_me_me
  113. TC_me_you
  114. context_it
  115. context_other
  116.  
  117. Finished in 0.0 seconds.
  118. 8 tests, 2 assertions, 0 failures, 0 errors
  119.  
  120. =end
Add Comment
Please, Sign In to add comment