app-tester 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +29 -27
- data/Rakefile +1 -16
- data/lib/app-tester/test.rb +41 -3
- data/lib/app-tester.rb +4 -8
- data/spec/app-tester_spec.rb +29 -35
- data/spec/spec_helper.rb +2 -0
- metadata +66 -2
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# Application Tester (app-tester)
|
2
2
|
|
3
|
-
* http://github.com/joseairosa/app-tester
|
3
|
+
* This page: http://github.com/joseairosa/app-tester
|
4
|
+
* Rubygems: http://rubygems.org/gems/app-tester
|
5
|
+
* Documentation: http://i.am.joseairosa.com/gems/app-tester/
|
4
6
|
|
5
7
|
[](http://travis-ci.org/joseairosa/app-tester)
|
6
8
|
|
7
|
-
##
|
9
|
+
## Description
|
8
10
|
|
9
11
|
This Gem will provide a framework to build command line functional tests against a web application (API, Website, etc)
|
10
12
|
|
11
|
-
##
|
13
|
+
## Features
|
12
14
|
|
13
15
|
* Easily create functional tests with just a few lines of code
|
14
16
|
* Since tests are built as command line tools they can be easily integrated with automatic tools
|
@@ -16,7 +18,7 @@ This Gem will provide a framework to build command line functional tests against
|
|
16
18
|
* Add colors to make your tests more readable and easier to understand
|
17
19
|
* Use pre-built tools to analyse your output or build your own
|
18
20
|
|
19
|
-
##
|
21
|
+
## Introduction
|
20
22
|
|
21
23
|
```ruby
|
22
24
|
require "app-tester"
|
@@ -29,16 +31,21 @@ apptester = AppTester.new do |options|
|
|
29
31
|
end
|
30
32
|
|
31
33
|
# Define your tests
|
32
|
-
apptester.define_test "my test" do |
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
apptester.define_test "my test" do |arguments, connection|
|
35
|
+
# Perform a get request to "/"
|
36
|
+
result1 = get "/"
|
37
|
+
# Perform a post request to "/" with token as parameter
|
38
|
+
result2 = get "/", :token => "hello"
|
39
|
+
# Perform a post request to "/"
|
40
|
+
result3 = post "/"
|
41
|
+
# Perform a post request to "/" with token as parameter
|
42
|
+
result4 = post "/", :token => "hello"
|
36
43
|
|
37
44
|
# Check if we have a 200 OK or not
|
38
|
-
AppTester::Checker.status
|
45
|
+
AppTester::Checker.status result1
|
39
46
|
|
40
47
|
# Convert a file to an array
|
41
|
-
p AppTester::Utils.file_to_array
|
48
|
+
p AppTester::Utils.file_to_array arguments[:file] unless arguments[:file].nil?
|
42
49
|
end
|
43
50
|
|
44
51
|
apptester.set_options_for "my test" do |options_parser|
|
@@ -78,13 +85,13 @@ Connecting to https://github.com...
|
|
78
85
|
[SUCCESS] got status 200
|
79
86
|
```
|
80
87
|
|
81
|
-
##
|
88
|
+
## Requirements
|
82
89
|
|
83
90
|
* json >= 1.7.5
|
84
91
|
* faraday >= 0.8.4
|
85
92
|
* optparse
|
86
93
|
|
87
|
-
##
|
94
|
+
## Intall
|
88
95
|
|
89
96
|
It's very easy to install.
|
90
97
|
|
@@ -109,10 +116,8 @@ apptester = AppTester.new do |options|
|
|
109
116
|
end
|
110
117
|
|
111
118
|
# Define your tests
|
112
|
-
apptester.define_test "my test" do |
|
113
|
-
result =
|
114
|
-
request.url "/"
|
115
|
-
end
|
119
|
+
apptester.define_test "my test" do |arguments, connection|
|
120
|
+
result = get "/"
|
116
121
|
|
117
122
|
puts "#{AppTester::Utils::Colours.red("Hello")} #{AppTester::Utils::Colours.green("World")}"
|
118
123
|
end
|
@@ -144,7 +149,7 @@ Available colours are:
|
|
144
149
|
You can benchmark your test. This is very useful to understand if anything is underperforming.
|
145
150
|
Tests can be nested inside each other.
|
146
151
|
|
147
|
-
```
|
152
|
+
```ruby
|
148
153
|
require "app-tester"
|
149
154
|
|
150
155
|
# Initialize framework with test environments
|
@@ -154,10 +159,8 @@ apptester = AppTester.new do |options|
|
|
154
159
|
end
|
155
160
|
|
156
161
|
# Define your tests
|
157
|
-
apptester.define_test "my test" do |
|
158
|
-
result =
|
159
|
-
request.url "/"
|
160
|
-
end
|
162
|
+
apptester.define_test "my test" do |arguments, connection|
|
163
|
+
result = get "/"
|
161
164
|
|
162
165
|
AppTester::Timer.new("test timer 1") do
|
163
166
|
sleep 1
|
@@ -191,7 +194,7 @@ We can have, for example, a functional test to an API where we want to run 100 s
|
|
191
194
|
|
192
195
|
Here is an example:
|
193
196
|
|
194
|
-
```
|
197
|
+
```ruby
|
195
198
|
require "app-tester"
|
196
199
|
|
197
200
|
apptester = AppTester.new do |options|
|
@@ -200,13 +203,12 @@ apptester = AppTester.new do |options|
|
|
200
203
|
options.default_environment = :google
|
201
204
|
end
|
202
205
|
|
203
|
-
apptester.define_test "my test" do |
|
204
|
-
result =
|
205
|
-
|
206
|
-
end
|
206
|
+
apptester.define_test "my test" do |arguments, connection|
|
207
|
+
result = get "/"
|
208
|
+
|
207
209
|
AppTester::Checker.status result
|
208
210
|
|
209
|
-
my_file = AppTester::Utils.file_to_array
|
211
|
+
my_file = AppTester::Utils.file_to_array arguments[:file]
|
210
212
|
|
211
213
|
my_file.each do |line|
|
212
214
|
# do awesome stuff with line
|
data/Rakefile
CHANGED
@@ -1,28 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gem 'hoe', '>= 2.1.0'
|
3
2
|
gem "json", "~> 1.7.5"
|
4
3
|
gem "faraday", "~> 0.8.4"
|
5
|
-
require 'hoe'
|
6
4
|
require 'fileutils'
|
7
5
|
require './lib/app-tester'
|
8
6
|
|
9
|
-
Hoe.plugin :newgem
|
10
|
-
# Hoe.plugin :website
|
11
|
-
# Hoe.plugin :cucumberfeatures
|
12
|
-
|
13
7
|
# Generate all the Rake tasks
|
14
|
-
# Run 'rake -T' to see list of generated tasks (from gem root
|
15
|
-
$hoe = Hoe.spec 'app-tester' do
|
16
|
-
self.developer 'Jose P. Airosa', 'me@joseairosa.com'
|
17
|
-
#self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
18
|
-
self.rubyforge_name = self.name # TODO this is default value
|
19
|
-
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
20
|
-
|
21
|
-
end
|
8
|
+
# Run 'rake -T' to see list of generated tasks (from gem root direct
|
22
9
|
|
23
|
-
require 'newgem/tasks'
|
24
10
|
Dir['tasks/**/*.rake'].each { |t| load t }
|
25
11
|
|
26
12
|
# TODO - want other tests/tasks run by default? Add them to the list
|
27
|
-
# remove_task :default
|
28
13
|
task :default => [:rspec]
|
data/lib/app-tester/test.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "rspec-expectations"
|
3
|
+
|
1
4
|
module AppTester
|
2
5
|
# @abstract Main object that hold all the data needed to run a test
|
3
6
|
# @attr_reader parser [AppTester::Parser] user selected options on command line
|
@@ -13,10 +16,14 @@ module AppTester
|
|
13
16
|
attr_reader :connection
|
14
17
|
attr_reader :options
|
15
18
|
|
16
|
-
|
19
|
+
attr_writer :self_before_instance_eval
|
20
|
+
|
21
|
+
include RSpec::Matchers
|
22
|
+
|
23
|
+
def initialize name, options={ }, &block
|
17
24
|
@name = name
|
18
25
|
@options = options
|
19
|
-
@source =
|
26
|
+
@source = block
|
20
27
|
@parser = AppTester::Parser.new(options)
|
21
28
|
@parser.banner = @name
|
22
29
|
end
|
@@ -26,6 +33,22 @@ module AppTester
|
|
26
33
|
yield(@parser) if block_given?
|
27
34
|
end
|
28
35
|
|
36
|
+
def arguments
|
37
|
+
@parser.options
|
38
|
+
end
|
39
|
+
|
40
|
+
def get url="", parameters={}
|
41
|
+
connection.get do |request|
|
42
|
+
request.url "/", parameters
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def post url="", parameters={}
|
47
|
+
connection.post do |request|
|
48
|
+
request.url url, parameters
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
29
52
|
# Run test
|
30
53
|
def run(arguments=ARGV)
|
31
54
|
append_help_option
|
@@ -33,7 +56,22 @@ module AppTester
|
|
33
56
|
# Make sure we have enough arguments
|
34
57
|
raise OptionParser::MissingArgument if @parser.mandatory_options + 2 > @parser.options.size + 1
|
35
58
|
@connection = AppTester::Connection.new @parser.options[:server], @options
|
36
|
-
@
|
59
|
+
@self_before_instance_eval = eval "self", @source.binding
|
60
|
+
begin
|
61
|
+
self.instance_eval &@source
|
62
|
+
rescue RSpec::Expectations::ExpectationNotMetError => excp
|
63
|
+
unless defined? IS_RSPEC
|
64
|
+
backtrace = excp.backtrace.map { |x|
|
65
|
+
x.match(/^(.+?):(\d+)(|:in `(.+)')$/);
|
66
|
+
[$1, $2, $4]
|
67
|
+
}
|
68
|
+
line_number = 0
|
69
|
+
backtrace.each do |array|
|
70
|
+
line_number = array[1] if array[2] == "block in <main>"
|
71
|
+
end
|
72
|
+
puts "#{AppTester::Utils::Strings::FAILED} #{excp.message} on line #{line_number}"
|
73
|
+
end
|
74
|
+
end
|
37
75
|
end
|
38
76
|
|
39
77
|
private
|
data/lib/app-tester.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
|
4
4
|
# @abstract AppTester main module and namespace
|
5
5
|
module AppTester
|
6
|
-
VERSION = '0.0
|
6
|
+
VERSION = '0.1.0'
|
7
7
|
|
8
8
|
# @abstract AppTester main class
|
9
9
|
# @attr_reader [AppTester::Options] Options container. This will be shared across other classes
|
@@ -36,9 +36,7 @@ module AppTester
|
|
36
36
|
#
|
37
37
|
# @param name [String] name for this test
|
38
38
|
#
|
39
|
-
# @yield
|
40
|
-
# @yieldparam cmd_options [AppTester::Parser] user selected options on command line
|
41
|
-
# @yieldparam connection [Faraday::Connection] the connection handler to the server selected on command line (or default fallback)
|
39
|
+
# @yield code snippet that will be executed when AppTester::Test.run is issued
|
42
40
|
#
|
43
41
|
# @return [AppTester::Test] if the creation of this test was successfull with a block
|
44
42
|
# @return [NilClass] if the creation of this test was successfull with no block
|
@@ -54,14 +52,12 @@ module AppTester
|
|
54
52
|
#
|
55
53
|
# p AppTester::Utils.file_to_array cmd_options[:file] unless cmd_options[:file].nil?
|
56
54
|
# end
|
57
|
-
def define_test name=""
|
55
|
+
def define_test name="", &block
|
58
56
|
if name.empty?
|
59
57
|
raise AppTester::Error::NameEmptyError, "Attempted to define a test without a name"
|
60
58
|
else
|
61
59
|
if block_given?
|
62
|
-
@tests[name.to_sym] = AppTester::Test.new(name, @options
|
63
|
-
yield cmd_options, connection
|
64
|
-
end
|
60
|
+
@tests[name.to_sym] = AppTester::Test.new(name, @options, &block)
|
65
61
|
else
|
66
62
|
@tests[name.to_sym] = nil
|
67
63
|
end
|
data/spec/app-tester_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe "App Tester framework" do
|
|
25
25
|
it "should return help when asked for it" do
|
26
26
|
apptester = start_app_tester
|
27
27
|
|
28
|
-
apptester.define_test "my test" do
|
28
|
+
apptester.define_test "my test" do
|
29
29
|
# blergh!
|
30
30
|
end
|
31
31
|
|
@@ -37,12 +37,12 @@ describe "App Tester framework" do
|
|
37
37
|
|
38
38
|
mock_arguments "-s" => "production"
|
39
39
|
|
40
|
-
apptester.define_test("test 1") do
|
41
|
-
|
40
|
+
apptester.define_test("test 1") do
|
41
|
+
arguments.should be_a(Hash)
|
42
42
|
connection.should be_a(Faraday::Connection)
|
43
43
|
end
|
44
|
-
apptester.define_test("test 2") do
|
45
|
-
|
44
|
+
apptester.define_test("test 2") do
|
45
|
+
arguments.should be_a(Hash)
|
46
46
|
connection.should be_a(Faraday::Connection)
|
47
47
|
end
|
48
48
|
apptester.tests.size.should eq(2)
|
@@ -53,8 +53,8 @@ describe "App Tester framework" do
|
|
53
53
|
it "should define a test without a default environment" do
|
54
54
|
apptester = start_app_tester
|
55
55
|
|
56
|
-
apptester.define_test "my test" do
|
57
|
-
|
56
|
+
apptester.define_test "my test" do
|
57
|
+
arguments[:server].should eq("localhost://production")
|
58
58
|
end
|
59
59
|
|
60
60
|
apptester.run_test("my test", [])
|
@@ -63,8 +63,8 @@ describe "App Tester framework" do
|
|
63
63
|
it "should define a test with a default environment" do
|
64
64
|
apptester = start_app_tester nil, :staging
|
65
65
|
|
66
|
-
apptester.define_test "my test" do
|
67
|
-
|
66
|
+
apptester.define_test "my test" do
|
67
|
+
arguments[:server].should eq("localhost://staging")
|
68
68
|
end
|
69
69
|
|
70
70
|
apptester.run_test("my test", [])
|
@@ -73,12 +73,12 @@ describe "App Tester framework" do
|
|
73
73
|
it "should define a test, set custom options and run" do
|
74
74
|
apptester = start_app_tester
|
75
75
|
|
76
|
-
apptester.define_test "my test" do
|
77
|
-
|
76
|
+
apptester.define_test "my test" do
|
77
|
+
arguments.should be_a(Hash)
|
78
78
|
connection.should be_a(Faraday::Connection)
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
arguments.size.should be(2)
|
80
|
+
arguments[:server].should_not be_empty
|
81
|
+
arguments[:smiles_file].should_not be_empty
|
82
82
|
end
|
83
83
|
|
84
84
|
apptester.set_options_for "my test" do |test_options|
|
@@ -93,7 +93,7 @@ describe "App Tester framework" do
|
|
93
93
|
it "should define a test, set custom options, define number mandatory options and run" do
|
94
94
|
apptester = start_app_tester
|
95
95
|
|
96
|
-
apptester.define_test "my test" do
|
96
|
+
apptester.define_test "my test" do
|
97
97
|
|
98
98
|
end
|
99
99
|
|
@@ -110,7 +110,7 @@ describe "App Tester framework" do
|
|
110
110
|
it "should create a connection" do
|
111
111
|
apptester = start_app_tester :production => "http://www.google.com"
|
112
112
|
|
113
|
-
apptester.define_test "my test" do
|
113
|
+
apptester.define_test "my test" do
|
114
114
|
connection.should be_a(Faraday::Connection)
|
115
115
|
end
|
116
116
|
|
@@ -122,12 +122,12 @@ describe "App Tester framework" do
|
|
122
122
|
it "should fetch contents of a connection" do
|
123
123
|
apptester = start_app_tester :production => "https://github.com"
|
124
124
|
|
125
|
-
apptester.define_test "my test" do
|
126
|
-
response =
|
127
|
-
req.url "/"
|
128
|
-
end
|
125
|
+
apptester.define_test "my test" do
|
126
|
+
response = get "/"
|
129
127
|
response.status.should eq(200)
|
130
128
|
response.body.should include("github")
|
129
|
+
response = post "/"
|
130
|
+
response.status.should eq(403)
|
131
131
|
end
|
132
132
|
|
133
133
|
mocked_arguments = mock_arguments "-s" => "production"
|
@@ -138,11 +138,9 @@ describe "App Tester framework" do
|
|
138
138
|
it "should return exception on connection failed" do
|
139
139
|
apptester = start_app_tester :production => "http://aoisjdioasjdioasjod"
|
140
140
|
|
141
|
-
apptester.define_test "my test" do
|
141
|
+
apptester.define_test "my test" do
|
142
142
|
begin
|
143
|
-
response =
|
144
|
-
req.url "/"
|
145
|
-
end
|
143
|
+
response = get "/"
|
146
144
|
rescue Exception => e
|
147
145
|
e.should be_a(Faraday::Error::ConnectionFailed)
|
148
146
|
end
|
@@ -156,10 +154,8 @@ describe "App Tester framework" do
|
|
156
154
|
it "should check status" do
|
157
155
|
apptester = start_app_tester :production => "https://github.com"
|
158
156
|
|
159
|
-
apptester.define_test "my test" do
|
160
|
-
response =
|
161
|
-
req.url "/"
|
162
|
-
end
|
157
|
+
apptester.define_test "my test" do
|
158
|
+
response = get "/"
|
163
159
|
AppTester::Checker.status response
|
164
160
|
end
|
165
161
|
|
@@ -173,10 +169,8 @@ describe "App Tester framework" do
|
|
173
169
|
it "should log connections if asked for" do
|
174
170
|
apptester = start_app_tester({ :production => "https://github.com" }, nil, true)
|
175
171
|
|
176
|
-
apptester.define_test "my test" do
|
177
|
-
response =
|
178
|
-
req.url "/"
|
179
|
-
end
|
172
|
+
apptester.define_test "my test" do
|
173
|
+
response = get "/"
|
180
174
|
end
|
181
175
|
|
182
176
|
mocked_arguments = mock_arguments "-s" => "production"
|
@@ -219,7 +213,7 @@ describe "App Tester framework" do
|
|
219
213
|
it "should time the execution" do
|
220
214
|
apptester = start_app_tester
|
221
215
|
|
222
|
-
apptester.define_test "my test" do
|
216
|
+
apptester.define_test "my test" do
|
223
217
|
AppTester::Timer.new("test timer") do
|
224
218
|
sleep 1
|
225
219
|
end
|
@@ -233,13 +227,13 @@ describe "App Tester framework" do
|
|
233
227
|
it "should time the execution with threshold" do
|
234
228
|
apptester = start_app_tester
|
235
229
|
|
236
|
-
apptester.define_test "my test 400 threshold" do
|
230
|
+
apptester.define_test "my test 400 threshold" do
|
237
231
|
AppTester::Timer.new("test timer", 400) do
|
238
232
|
sleep 0.5
|
239
233
|
end
|
240
234
|
end
|
241
235
|
|
242
|
-
apptester.define_test "my test 600 threshold" do
|
236
|
+
apptester.define_test "my test 600 threshold" do
|
243
237
|
AppTester::Timer.new("test timer", 600) do
|
244
238
|
sleep 0.5
|
245
239
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app-tester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,6 +43,70 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.8.4
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.11.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.11.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec-expectations
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.11.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.11.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
46
110
|
description: Command-line Framework to run functional tests against a web application
|
47
111
|
(API, Website, etc)
|
48
112
|
email: me@joseairosa.com
|
@@ -72,7 +136,7 @@ files:
|
|
72
136
|
homepage: https://github.com/joseairosa/app-tester
|
73
137
|
licenses:
|
74
138
|
- MIT
|
75
|
-
post_install_message: ! "\e[0;32mThanks for installing! You're awesome ^_^\e[0m"
|
139
|
+
post_install_message: ! "\e[0;32mThanks for installing! You're awesome! ^_^\e[0m"
|
76
140
|
rdoc_options: []
|
77
141
|
require_paths:
|
78
142
|
- lib
|