testingmachine 0.1.7
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/LICENSE +20 -0
- data/README.rdoc +22 -0
- data/TODO +4 -0
- data/bin/tm +35 -0
- data/lib/generators/tm/feature_generator.rb +26 -0
- data/lib/generators/tm/install_generator.rb +20 -0
- data/lib/generators/tm/templates/config.yml +11 -0
- data/lib/generators/tm/templates/feature_spec.rb +7 -0
- data/lib/generators/tm/templates/helper.rb +6 -0
- data/lib/generators/tm/templates/table.table +10 -0
- data/lib/testingmachine.rb +1 -0
- data/lib/tm/configuration.rb +40 -0
- data/lib/tm/parse/plain_text.rb +79 -0
- data/lib/tm/parse.rb +6 -0
- data/lib/tm/table.rb +11 -0
- data/lib/tm.rb +65 -0
- metadata +111 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jinzhu
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= Testing Machine
|
2
|
+
|
3
|
+
Your trusty, tireless testing machine
|
4
|
+
|
5
|
+
How To Install
|
6
|
+
$ gem install testingmachine
|
7
|
+
|
8
|
+
http://github.com/jinzhu/testingmachine
|
9
|
+
|
10
|
+
== Note on Patches/Pull Requests
|
11
|
+
|
12
|
+
* Fork the project.
|
13
|
+
* Make your feature addition or bug fix.
|
14
|
+
* Add tests for it. This is important so I don't break it in a
|
15
|
+
future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history.
|
17
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
18
|
+
* Send me a pull request. Bonus points for topic branches.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2010 Jinzhu. See LICENSE for details.
|
data/TODO
ADDED
data/bin/tm
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require File.expand_path('../lib/tm',File.dirname(__FILE__))
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: tm -t types file1 file2 / directoris"
|
9
|
+
|
10
|
+
opts.on( '-t', '--type types', 'types' ) do |types|
|
11
|
+
TM::Configuration.types = types.split(',').map(&:to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
15
|
+
puts opts
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.parse!
|
20
|
+
end
|
21
|
+
|
22
|
+
ARGV.push(TM::Configuration.root) if ARGV.size == 0
|
23
|
+
|
24
|
+
ARGV.map do |f|
|
25
|
+
TM::Configuration.root = File.expand_path(f)
|
26
|
+
$LOAD_PATH.unshift(TM::Configuration.root)
|
27
|
+
|
28
|
+
if File.file?(f)
|
29
|
+
require f
|
30
|
+
elsif File.directory?(f)
|
31
|
+
Dir["#{f}/**/*_spec.rb"].map { |x| require x }
|
32
|
+
end
|
33
|
+
|
34
|
+
$LOAD_PATH.shift
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module TM
|
4
|
+
class FeatureGenerator < Rails::Generators::Base
|
5
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
6
|
+
|
7
|
+
desc <<-DESC
|
8
|
+
Description:
|
9
|
+
Sets up WebTM for your Rails project.
|
10
|
+
`rails generate tm:feature filename`
|
11
|
+
DESC
|
12
|
+
|
13
|
+
def manifest
|
14
|
+
ARGV.map do |name|
|
15
|
+
@name = name.gsub(/[A-Z]/) {|x| '_' + x.downcase }.sub(/^_/,'').gsub(/\/_/,'/')
|
16
|
+
spec_filename = "testingmachine/features/#{@name}_spec.rb"
|
17
|
+
table_filename = "testingmachine/tables/#{@name}.table"
|
18
|
+
@const_name = File.basename(@name).capitalize.gsub(/_(\w)/) { $1.capitalize }
|
19
|
+
|
20
|
+
empty_directory File.dirname(spec_filename)
|
21
|
+
template "feature_spec.rb", spec_filename
|
22
|
+
template "table.table", table_filename
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module TM
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
6
|
+
|
7
|
+
desc <<-DESC
|
8
|
+
Description:
|
9
|
+
Sets up WebTM for your Rails project.
|
10
|
+
`rails generate tm:install`
|
11
|
+
DESC
|
12
|
+
|
13
|
+
def manifest
|
14
|
+
empty_directory 'testingmachine/features'
|
15
|
+
empty_directory 'testingmachine/tables'
|
16
|
+
copy_file 'config.yml', 'config/testingmachine.yml'
|
17
|
+
copy_file 'helper.rb', 'testingmachine/helper.rb'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
write your fixture here
|
2
|
+
|
3
|
+
Example:
|
4
|
+
|
5
|
+
In order to post a article you need to login first
|
6
|
+
|
7
|
+
== post a article > login to admin page
|
8
|
+
| username | password | message |
|
9
|
+
| jinzhu | right_password | /login successful/ |
|
10
|
+
| jinzhu | wrong_password | /login fail/ |
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'tm.rb')
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module TM
|
4
|
+
class Configuration
|
5
|
+
class << self
|
6
|
+
attr_accessor :types, :root
|
7
|
+
|
8
|
+
def root
|
9
|
+
test_path = File.expand_path('testingmachine')
|
10
|
+
@root ||= File.exist?(test_path) ? test_path : File.expand_path('.')
|
11
|
+
end
|
12
|
+
|
13
|
+
def root=(path)
|
14
|
+
@root = path if File.directory?(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
['config', '../config'].map do |f|
|
19
|
+
config_file = File.join( root, f, 'testingmachine.yml')
|
20
|
+
return YAML.load_file(config_file) if File.exist?(config_file)
|
21
|
+
end
|
22
|
+
return {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_setting_for_types(types=[])
|
26
|
+
types = types.to_a.unshift(:all)
|
27
|
+
types.map do |type|
|
28
|
+
config = self.config['types'] && self.config['types'][type.to_s]
|
29
|
+
load_config(config)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_config(config)
|
34
|
+
## load configuration for Capybara
|
35
|
+
capybara_config = config && config['capybara']
|
36
|
+
capybara_config.map { |f| Capybara.send((f[0] + '=').to_sym, f[1]) } if capybara_config
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module TM
|
2
|
+
module Parse
|
3
|
+
class PlainText
|
4
|
+
@@data = {}
|
5
|
+
attr_accessor :file, :name, :headers
|
6
|
+
|
7
|
+
def initialize(file, name)
|
8
|
+
self.file, self.name = file, name
|
9
|
+
@@data[file] ||= {}
|
10
|
+
@@data[file][name] ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.[](file, name)
|
14
|
+
parse(file) unless @@data[file]
|
15
|
+
(@@data[file] && @@data[file][name]) || []
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_row(values)
|
19
|
+
values = values.sub(/^\|/,'').sub(/\|\s*$/,'').split(' | ').map(&:strip)
|
20
|
+
return(set_header(values)) if headers.nil?
|
21
|
+
|
22
|
+
@@data[file][name].push PlainText::Row.new(values, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def self.parse(file)
|
27
|
+
table = nil
|
28
|
+
absolute_filepath = File.join(TM::Configuration.root + '/tables/', file + '.table')
|
29
|
+
return unless File.exist?(absolute_filepath)
|
30
|
+
|
31
|
+
File.read(absolute_filepath).each_line do |line|
|
32
|
+
if line =~ /^== (.*)$/
|
33
|
+
table = self.new(file, $1.strip)
|
34
|
+
end
|
35
|
+
|
36
|
+
if table && line =~ /^\|\s/
|
37
|
+
table.add_row(line)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_header(values)
|
43
|
+
## hash has no order
|
44
|
+
self.headers = values
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class PlainText::Row
|
49
|
+
attr_accessor :values, :headers
|
50
|
+
|
51
|
+
def initialize(values, headers)
|
52
|
+
self.values, self.headers = [], headers
|
53
|
+
|
54
|
+
[values, headers].transpose.map do |value, header|
|
55
|
+
self.instance_eval <<-EOF
|
56
|
+
def #{header}
|
57
|
+
@#{header} ||= #{value} rescue #{value.inspect}
|
58
|
+
end
|
59
|
+
EOF
|
60
|
+
|
61
|
+
self.values.push PlainText::Attribute.new(value, header)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# def method_missing(method_name, *args, &block)
|
66
|
+
# self.values.send(method_name, *args, &block)
|
67
|
+
# end
|
68
|
+
end
|
69
|
+
|
70
|
+
class PlainText::Attribute
|
71
|
+
attr_accessor :value, :header
|
72
|
+
|
73
|
+
def initialize(value, header)
|
74
|
+
self.value, self.header = value, header
|
75
|
+
end
|
76
|
+
alias :to_s :value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/tm/parse.rb
ADDED
data/lib/tm/table.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module TM
|
2
|
+
class Table
|
3
|
+
def self.[] test_file, name
|
4
|
+
parse_format = TM::Configuration.config['table_format'] || 'plain_text'
|
5
|
+
table_file = test_file.sub(/_spec\.rb$/,'').sub(/^#{TM::Configuration.root}\/features\//,'')
|
6
|
+
## constantize: plain_text => PlainText
|
7
|
+
parse_format = parse_format.capitalize.gsub(/_(\w)/) { $1.capitalize }
|
8
|
+
return TM::Parse.const_get(parse_format)[table_file, name.strip]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/tm.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
require 'rubygems'
|
3
|
+
require 'capybara'
|
4
|
+
require 'capybara/dsl'
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'tm/configuration'
|
7
|
+
require 'tm/parse'
|
8
|
+
require 'tm/table'
|
9
|
+
|
10
|
+
Capybara.default_driver = :selenium
|
11
|
+
MiniTest::Unit.autorun
|
12
|
+
|
13
|
+
module TM
|
14
|
+
def self.should_run_type?(types)
|
15
|
+
return true if TM::Configuration.types.nil?
|
16
|
+
return false if types.nil?
|
17
|
+
types = types.to_a.map(&:to_s)
|
18
|
+
(types - TM::Configuration.types) != types
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class MiniTest::Spec
|
23
|
+
include Capybara
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def scenario desc, opts = {}, &block
|
27
|
+
return unless TM.should_run_type?(opts[:type])
|
28
|
+
TM::Configuration.load_setting_for_types(opts[:type])
|
29
|
+
test_file = File.expand_path(caller[0].sub(/:.*$/,''))
|
30
|
+
|
31
|
+
it desc do
|
32
|
+
data_table = TM::Table[test_file, desc]
|
33
|
+
|
34
|
+
if !data_table.empty?
|
35
|
+
data_table.map do |example|
|
36
|
+
instance_variable_set("@_headers", example.headers)
|
37
|
+
example.headers.map do |header|
|
38
|
+
instance_variable_set("@#{header}", example.send(header.to_sym))
|
39
|
+
end
|
40
|
+
self.instance_exec(&block)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
self.instance_exec(&block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
alias :Scenario :scenario
|
48
|
+
|
49
|
+
def background type = :each, opts = {}, &block
|
50
|
+
return unless TM.should_run_type?(opts[:type])
|
51
|
+
|
52
|
+
before type do
|
53
|
+
self.instance_exec(&block)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
alias :Background :background
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module Kernel
|
61
|
+
def feature desc, opts = {}, &block
|
62
|
+
describe desc, &block
|
63
|
+
end
|
64
|
+
alias :Feature :feature
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testingmachine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jinzhu
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-12 00:00:00 +08:00
|
19
|
+
default_executable: tm
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: minitest
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: capybara
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: your trusty, tireless Testing Machine
|
50
|
+
email: wosmvp@gmail.com
|
51
|
+
executables:
|
52
|
+
- tm
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
- TODO
|
59
|
+
files:
|
60
|
+
- lib/generators/tm/feature_generator.rb
|
61
|
+
- lib/generators/tm/install_generator.rb
|
62
|
+
- lib/generators/tm/templates/config.yml
|
63
|
+
- lib/generators/tm/templates/feature_spec.rb
|
64
|
+
- lib/generators/tm/templates/helper.rb
|
65
|
+
- lib/generators/tm/templates/table.table
|
66
|
+
- lib/testingmachine.rb
|
67
|
+
- lib/tm.rb
|
68
|
+
- lib/tm/configuration.rb
|
69
|
+
- lib/tm/parse.rb
|
70
|
+
- lib/tm/parse/plain_text.rb
|
71
|
+
- lib/tm/table.rb
|
72
|
+
- LICENSE
|
73
|
+
- README.rdoc
|
74
|
+
- TODO
|
75
|
+
- bin/tm
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/jinzhu/testingmachine
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.3.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: your trusty, tireless Testing Machine
|
110
|
+
test_files: []
|
111
|
+
|