henry-crash_dummy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55fed373c5c03e431b9e69cbe809ed6025b1c11f
4
+ data.tar.gz: 64b8d473044fec8986c28199f5f876643a5b5fc1
5
+ SHA512:
6
+ metadata.gz: 5d94f42dd342269585def73aac0ab8d1053568a155e0efe81dddb02e3f45e61ed47eb6bfa2bd6d592f143ba78a3ed9db72415a0cee6760d2eb5c4c8c06ab432f
7
+ data.tar.gz: 279b4f35e6fd0fb5e1fd1fa948f83c4d7fa07e9c66f89cff79d630cc5093db29144d08cc6161661ddef76057144b85fe85f725800f1e550ae05b3e2724693fcf
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ henry-crash_dummy (0.0.1)
5
+ henry-container
6
+ watir-webdriver
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ansi (1.4.3)
12
+ builder (3.2.0)
13
+ childprocess (0.3.9)
14
+ ffi (~> 1.0, >= 1.0.11)
15
+ colorize (0.5.8)
16
+ cucumber (1.3.2)
17
+ builder (>= 2.1.2)
18
+ diff-lcs (>= 1.1.3)
19
+ gherkin (~> 2.12.0)
20
+ multi_json (~> 1.3)
21
+ diff-lcs (1.2.4)
22
+ ffi (1.8.1)
23
+ gherkin (2.12.0)
24
+ multi_json (~> 1.3)
25
+ hashie (2.0.5)
26
+ henry-container (0.1.34)
27
+ colorize
28
+ cucumber
29
+ mail
30
+ minitest-reporters
31
+ rake
32
+ rspec (~> 2)
33
+ trollop
34
+ mail (2.5.4)
35
+ mime-types (~> 1.16)
36
+ treetop (~> 1.4.8)
37
+ mime-types (1.23)
38
+ minitest (4.7.4)
39
+ minitest-reporters (0.14.19)
40
+ ansi
41
+ builder
42
+ minitest (>= 2.12, < 5.0)
43
+ powerbar
44
+ multi_json (1.7.3)
45
+ polyglot (0.3.3)
46
+ powerbar (1.0.11)
47
+ ansi (~> 1.4.0)
48
+ hashie (>= 1.1.0)
49
+ rake (10.0.4)
50
+ rspec (2.13.0)
51
+ rspec-core (~> 2.13.0)
52
+ rspec-expectations (~> 2.13.0)
53
+ rspec-mocks (~> 2.13.0)
54
+ rspec-core (2.13.1)
55
+ rspec-expectations (2.13.0)
56
+ diff-lcs (>= 1.1.3, < 2.0)
57
+ rspec-mocks (2.13.1)
58
+ rubyzip (0.9.9)
59
+ selenium-webdriver (2.32.1)
60
+ childprocess (>= 0.2.5)
61
+ multi_json (~> 1.0)
62
+ rubyzip
63
+ websocket (~> 1.0.4)
64
+ treetop (1.4.12)
65
+ polyglot
66
+ polyglot (>= 0.3.1)
67
+ trollop (2.0)
68
+ watir-webdriver (0.6.4)
69
+ selenium-webdriver (>= 2.18.0)
70
+ websocket (1.0.7)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ henry-crash_dummy!
77
+ rake
78
+ rspec
@@ -0,0 +1,97 @@
1
+ module Henry
2
+
3
+ # Henry Dummy class holding methods to emulate testing behaviours.
4
+ class Dummy
5
+
6
+ # Collection of possibleexceptions to be thrown by the #browser method.
7
+ module BrowserException
8
+ # Exception thrown whenever the title comparison fails.
9
+ class TitleMismatch < Exception; end
10
+ end
11
+
12
+ # @param [Henry::Task] task the task to play with.
13
+ def initialize(task)
14
+ @task = task
15
+ end
16
+
17
+ # Opens a browser, navigate the given url and asserts the page title.
18
+ #
19
+ # @param [String,Symbol] driver the web driver name to be used.
20
+ # @param [String] url the url to navigate.
21
+ # @param [String] text the expected title name (or partial name).
22
+ def browser(driver, url, text)
23
+ navigator = Henry::Navigator.new(driver)
24
+
25
+ title = navigator.navigate(url).title
26
+
27
+ navigator.close
28
+
29
+ raise BrowserException::TitleMismatch if !title.include?(text)
30
+ end
31
+
32
+ # Produces CPU usage fot the given amount of time.
33
+ #
34
+ # @param [Integer] seconds how long the CPU will be used.
35
+ # @param [Integer] interval amount of CPU cycles before slowing down.
36
+ def cpu(seconds, interval=nil)
37
+ Timeout::timeout(seconds) do
38
+ loop do
39
+ slow_down(interval) if interval
40
+ end
41
+ end
42
+
43
+ rescue Timeout::Error
44
+ end
45
+
46
+ # Creates a file (and its path) adn writes the given content.
47
+ #
48
+ # @param [String] name the file name.
49
+ # @param [String] path the target file path.
50
+ # @param [String] content the content to be written in the file content the content to be written in the file.
51
+ def file(name, path, content)
52
+ FileUtils.mkpath(path)
53
+
54
+ File.open("#{path}/#{name}", 'w') do |file|
55
+ file.write(content)
56
+ end
57
+ end
58
+
59
+ # Overwrites the execution message with the give value.
60
+ #
61
+ # @param [String] message the message to set into the execution.
62
+ def message(message)
63
+ @task.execution.message = message
64
+ end
65
+
66
+ # Overwrites the execution code with the given value.
67
+ #
68
+ # @param [String] code the code to set into the execution.
69
+ def return_code(code)
70
+ @task.execution.code = code
71
+ end
72
+
73
+ # Raises an exception
74
+ def runtime_error
75
+ raise Exception
76
+ end
77
+
78
+ # Sleeps the process for the given amount for seconds.
79
+ #
80
+ # @param [Integer] seconds how long the process will sleep.
81
+ def sleep(seconds)
82
+ Kernel.sleep(seconds)
83
+ end
84
+
85
+ private
86
+
87
+ # Sleeps the process every interva CPU cycles.
88
+ #
89
+ # @param [Integer] interval amount of CPU cycles before sleep should be called.
90
+ def slow_down(interval)
91
+ interval.times {}
92
+ Kernel.sleep(0.99)
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,45 @@
1
+ require 'watir-webdriver'
2
+
3
+ module Henry
4
+
5
+ # Defines a common interface for managing bowsers.
6
+ class Navigator
7
+
8
+ def initialize(driver)
9
+ @driver = driver
10
+ end
11
+
12
+ # Closes the curretn browser
13
+ def close
14
+ browser.close
15
+ end
16
+
17
+ # Navigates the given URL
18
+ #
19
+ # @param [String] ulr the target URL.
20
+ # @return [Henry::Navigator] enabling chaining methods.
21
+ def navigate(url)
22
+ browser.goto(url)
23
+
24
+ return self
25
+ end
26
+
27
+ # Returns the curretn browser title.
28
+ #
29
+ # @return [String] the browser title.
30
+ def title
31
+ browser.title
32
+ end
33
+
34
+ private
35
+
36
+ # Initialze and returns a browser instance.
37
+ #
38
+ # @return [Watir::Browser] the browser instance.
39
+ def browser
40
+ @browser ||= Watir::Browser.new(@driver)
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,46 @@
1
+ module Henry
2
+
3
+ class Task
4
+
5
+ class DummyTask < Task
6
+
7
+ # Configures the Task.
8
+ #
9
+ # @param [Hash] params the task params.
10
+ # @param [Hash] extended_context task extended context.
11
+ def configure(params, extended_context={})
12
+ @actions = (params['actions'] || []).collect do |action|
13
+ OpenStruct.new({
14
+ command: action['type'].downcase.to_sym,
15
+ params: action['arguments']
16
+ })
17
+ end
18
+ end
19
+
20
+ # Process the params and seets the execution params based on them.
21
+ def execute
22
+ abort 'You must configure the task before execution.' if @actions.nil?
23
+
24
+ dummy = Henry::Dummy.new(self)
25
+
26
+ @actions.each do |action|
27
+ dummy.send(action.command, *action.params)
28
+ end
29
+
30
+ self.execution.code ||= 'OK'
31
+ self.execution.message ||= 'OK'
32
+ self.execution.log ||= []
33
+ self.execution.output ||= 'OK'
34
+ rescue Exception => e
35
+ self.execution.code ||= 'ERROR'
36
+ self.execution.message ||= e.message
37
+ self.execution.log ||= []
38
+ self.execution.backtrace ||= e.backtrace
39
+ self.execution.output ||= 'ERROR'
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
data/lib/henry.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ require 'fileutils'
3
+ require 'henry'
4
+
5
+ require_relative 'henry/dummy'
6
+ require_relative 'henry/navigator'
7
+ require_relative 'henry/task/dummy_task'
8
+
9
+ module Henry
10
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.authors = ['Roberto Decurnex']
3
+ s.date = '2013-05-24'
4
+ s.email = 'decurnex.roberto@gmail.com'
5
+ s.homepage = 'http://gitorious.despegar.it/henry-self-test/ruby-crash-dummy'
6
+ s.name = 'henry-crash_dummy'
7
+ s.summary = 'Henry library to recreate testing scenarios.'
8
+ s.version = '0.0.1'
9
+
10
+ s.require_paths = ['lib']
11
+
12
+ s.files = [
13
+ 'Gemfile',
14
+ 'Gemfile.lock',
15
+ 'lib/henry.rb',
16
+ 'lib/henry/dummy.rb',
17
+ 'lib/henry/navigator.rb',
18
+ 'lib/henry/task/dummy_task.rb',
19
+ 'ruby-crash-dummy.gemspec'
20
+ ]
21
+
22
+ s.add_dependency 'henry-container'
23
+ s.add_dependency 'watir-webdriver'
24
+
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec'
27
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: henry-crash_dummy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Decurnex
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: henry-container
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: watir-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: decurnex.roberto@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - lib/henry.rb
78
+ - lib/henry/dummy.rb
79
+ - lib/henry/navigator.rb
80
+ - lib/henry/task/dummy_task.rb
81
+ - ruby-crash-dummy.gemspec
82
+ homepage: http://gitorious.despegar.it/henry-self-test/ruby-crash-dummy
83
+ licenses: []
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Henry library to recreate testing scenarios.
105
+ test_files: []
106
+ has_rdoc: