Class: Henry::Dummy

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(task) ⇒ Dummy

Returns a new instance of Dummy.

Parameters:



21
22
23
# File 'lib/henry/dummy.rb', line 21

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.

Parameters:

  • driver (String, Symbol)

    the web driver name to be used.

  • url (String)

    the url to navigate.

  • text (String)

    the expected title name (or partial name).

Raises:



30
31
32
33
34
35
36
37
38
# File 'lib/henry/dummy.rb', line 30

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.

Parameters:

  • seconds (Integer)

    how long the CPU will be used.

  • interval (Integer) (defaults to: nil)

    amount of CPU cycles before slowing down.



44
45
46
47
48
49
50
51
52
# File 'lib/henry/dummy.rb', line 44

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.

Parameters:

  • name (String)

    the file name.

  • path (String)

    the target file path.

  • content (String)

    the content to be written in the file content the content to be written in the file.



59
60
61
62
63
64
65
# File 'lib/henry/dummy.rb', line 59

def file(name, path, content)
  FileUtils.mkpath("#{Henry::Environment.config['output_directory']}/#{path}")

  File.open("#{Henry::Environment.config['output_directory']}/#{path}/#{name}", 'w') do |file|
    file.write(content)
  end
end

#girdObject



67
68
# File 'lib/henry/dummy.rb', line 67

def gird
end

#log(message, repetitions = 1) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/henry/dummy.rb', line 83

def log(message, repetitions=1)
  @task.execution.log ||= []
 
  repetitions.times do
    @task.execution.log << message
  end
end

#mapObject



70
71
# File 'lib/henry/dummy.rb', line 70

def map
end

#memoryObject



73
74
# File 'lib/henry/dummy.rb', line 73

def memory
end

#message(message) ⇒ Object

Overwrites the execution message with the give value.

Parameters:

  • message (String)

    the message to set into the execution.



79
80
81
# File 'lib/henry/dummy.rb', line 79

def message(message)
  @task.execution.message = message
end

#return_code(code) ⇒ Object

Overwrites the execution code with the given value.

Parameters:

  • code (String)

    the code to set into the execution.



94
95
96
# File 'lib/henry/dummy.rb', line 94

def return_code(code)
  @task.execution.code = code
end

#runtime_errorObject

Raises an exception

Raises:

  • (Exception)


99
100
101
# File 'lib/henry/dummy.rb', line 99

def runtime_error
  raise Exception
end

#sleep(seconds) ⇒ Object

Sleeps the process for the given amount for seconds.

Parameters:

  • seconds (Integer)

    how long the process will sleep.



106
107
108
# File 'lib/henry/dummy.rb', line 106

def sleep(seconds)
  Kernel.sleep(seconds)
end