Class: SeaCucumber::TestRunner

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/seacucumber.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ TestRunner

Returns a new instance of TestRunner.



32
33
34
35
36
37
38
39
40
# File 'lib/seacucumber.rb', line 32

def initialize(&block)
  @name = options[:name]
  @host = options[:host]
  @port = options[:port]
  @tests = []
  @queue = Queue.new

  define(&block)
end

Class Attribute Details

.browsersObject

Returns the value of attribute browsers.



30
31
32
# File 'lib/seacucumber.rb', line 30

def browsers
  @browsers
end

.optionsObject

Returns the value of attribute options.



30
31
32
# File 'lib/seacucumber.rb', line 30

def options
  @options
end

Instance Method Details

#defineObject



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
# File 'lib/seacucumber.rb', line 42

def define
  task @name do
    result = []

    # Starting the server...
    # NOTE: this must be within the task, otherwise the server will be started regardless of whether the task was called
    puts "Starting WEBrick server (listening on #{@port})..."
    @server = WEBrick::HTTPServer.new(:Port => @port)
    @server.mount_proc("/results") do |req, res|
      @queue.push(req.query['result'])
      res.body = "OK"
    end

    yield self if block_given?

    trap("INT") { @server.shutdown }
    thread = Thread.new { @server.start }

    # run all combinations of browsers and tests
    browsers.values.each do |browser|
      if browser.supported?
        browser.setup
        @tests.each do |test|
          browser.visit("http://#{@host}:#{@port}/#{test}?resultsURL=http://#{@host}:#{@port}/results&t=" + ("%.6f" % Time.now.to_f))
          result = @queue.pop
          puts "Testing '#{test}' on #{browser}: #{result}"
        end
      else
        puts "Skipping #{browser}, not supported on this OS"
      end

      browser.teardown
    end

    @server.shutdown
    thread.join
  end
end

#mount(path, dir = nil) ⇒ Object



81
82
83
84
85
# File 'lib/seacucumber.rb', line 81

def mount(path, dir=nil)
  dir = Dir.pwd + path unless dir

  @server.mount(path, WEBrick::HTTPServlet::FileHandler, dir)
end

#run(test) ⇒ Object

test should be specified as a url



88
89
90
# File 'lib/seacucumber.rb', line 88

def run(test)
  @tests << test
end