Class: Henry::Dummy
- Inherits:
-
Object
- Object
- Henry::Dummy
- Defined in:
- lib/henry/dummy.rb
Overview
Henry Dummy class holding methods to emulate testing behaviours.
Defined Under Namespace
Modules: BrowserException
Instance Method Summary collapse
-
#browser(driver, url, text) ⇒ Object
Opens a browser, navigate the given url and asserts the page title.
-
#cpu(seconds, interval = nil) ⇒ Object
Produces CPU usage fot the given amount of time.
-
#file(name, path, content) ⇒ Object
Creates a file (and its path) adn writes the given content.
-
#initialize(task) ⇒ Dummy
constructor
A new instance of Dummy.
-
#message(message) ⇒ Object
Overwrites the execution message with the give value.
-
#return_code(code) ⇒ Object
Overwrites the execution code with the given value.
-
#runtime_error ⇒ Object
Raises an exception.
-
#sleep(seconds) ⇒ Object
Sleeps the process for the given amount for seconds.
Constructor Details
#initialize(task) ⇒ Dummy
Returns a new instance of Dummy.
13 14 15 |
# File 'lib/henry/dummy.rb', line 13 def initialize(task) @task = task end |
Instance Method Details
#browser(driver, url, text) ⇒ Object
Opens a browser, navigate the given url and asserts the page title.
22 23 24 25 26 27 28 29 30 |
# File 'lib/henry/dummy.rb', line 22 def browser(driver, url, text) navigator = Henry::Navigator.new(driver) title = navigator.navigate(url).title navigator.close raise BrowserException::TitleMismatch if !title.include?(text) end |
#cpu(seconds, interval = nil) ⇒ Object
Produces CPU usage fot the given amount of time.
36 37 38 39 40 41 42 43 44 |
# File 'lib/henry/dummy.rb', line 36 def cpu(seconds, interval=nil) Timeout::timeout(seconds) do loop do slow_down(interval) if interval end end rescue Timeout::Error end |
#file(name, path, content) ⇒ Object
Creates a file (and its path) adn writes the given content.
51 52 53 54 55 56 57 |
# File 'lib/henry/dummy.rb', line 51 def file(name, path, content) FileUtils.mkpath(path) File.open("#{path}/#{name}", 'w') do |file| file.write(content) end end |
#message(message) ⇒ Object
Overwrites the execution message with the give value.
62 63 64 |
# File 'lib/henry/dummy.rb', line 62 def () @task.execution. = end |
#return_code(code) ⇒ Object
Overwrites the execution code with the given value.
69 70 71 |
# File 'lib/henry/dummy.rb', line 69 def return_code(code) @task.execution.code = code end |
#runtime_error ⇒ Object
Raises an exception
74 75 76 |
# File 'lib/henry/dummy.rb', line 74 def runtime_error raise Exception end |
#sleep(seconds) ⇒ Object
Sleeps the process for the given amount for seconds.
81 82 83 |
# File 'lib/henry/dummy.rb', line 81 def sleep(seconds) Kernel.sleep(seconds) end |