Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # using test/spec behave type methods in TestUnit classes
- require 'test/spec'
- require 'watir/testcase'
- class TC_me < Watir::TestCase
- def test_me
- 'bla'.should == 'bla'
- puts "TC_me_me"
- end
- def test_you
- 1.should.be 1
- puts 'TC_me_you'
- end
- end
- class TC_abc < Watir::TestCase
- def test_bla
- true.should.be true
- puts "TC_wow_bla"
- end
- def test_yay
- false.should.be false
- puts "TC_wow_yay"
- end
- end
- # this will not be picked up by the Spy. that's ok
- context 'HelloWorld Context Name' do
- it 'the it method' do
- true.should.be true
- puts 'context_it'
- end
- it 'some other thing' do
- true.should.be true
- puts 'context_other'
- end
- end
- class TC_wow < Watir::TestCase
- def test_bla
- true.should.be true
- puts "TC_wow_bla"
- end
- def test_yay
- false.should.be false
- puts "TC_wow_yay"
- end
- end
- module TestSpaceSpy
- class << self
- def tests
- # finding what tests are loaded in ObjectSpace
- tests =[]
- ObjectSpace.each_object(Class)do |klass|
- if(Test::Unit::TestCase > klass)
- tests << klass.suite unless klass == Watir::TestCase
- end
- end
- tests.reverse #TODO I don't know why I need to reverse this to have sequential here
- end
- def to_a
- out =[]
- tests.each do |test|
- rec =[];rec << test.name
- srec = [];test.tests.each {|tm| srec << tm.method_name};rec << srec
- out << rec
- end
- out
- end
- def to_yaml
- YAML.dump(to_a)
- end
- end
- end
- # get the yaml representation of all TestCases loaded in ObjectSpace
- puts 'Watir TestCases to Run'
- p TestSpaceSpy.to_a
- puts TestSpaceSpy.to_yaml
- =begin
- [["TC_me", ["test_me", "test_you"]],
- ["TC_abc", ["test_bla", "test_yay"]],
- ["HelloWorld Context Name", ["test_spec {HelloWorld Context Name} 001 [the it method]", "test_spec {HelloWorld Context Name} 002 [some other thing]"]],
- ["TC_wow", ["test_bla", "test_yay"]]]
- ---
- - - TC_me
- - - test_me
- - test_you
- - - TC_abc
- - - test_bla
- - test_yay
- - - HelloWorld Context Name
- - - test_spec {HelloWorld Context Name} 001 [the it method]
- - test_spec {HelloWorld Context Name} 002 [some other thing]
- - - TC_wow
- - - test_bla
- - test_yay
- Loaded suite <bla>
- Started
- TC_wow_bla
- TC_wow_yay
- TC_wow_bla
- TC_wow_yay
- TC_me_me
- TC_me_you
- context_it
- context_other
- Finished in 0.0 seconds.
- 8 tests, 2 assertions, 0 failures, 0 errors
- =end
Add Comment
Please, Sign In to add comment