protester 0.1.3

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 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.
@@ -0,0 +1,22 @@
1
+ = WebTester
2
+
3
+ Your trusty, tireless tester
4
+
5
+ How To Install
6
+ $ gem install webtester
7
+
8
+ https://github.com/jinzhu/webtester
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
@@ -0,0 +1,4 @@
1
+ 1, more table parser adapters: excel sql(web interface)?
2
+ 2, support multi tables?
3
+ 3, rake task
4
+ 4, write more test
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require File.expand_path('../lib/tester',File.dirname(__FILE__))
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: webtester -t types file1 file2 / directoris"
9
+
10
+ opts.on( '-t', '--type types', 'types' ) do |types|
11
+ Tester::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(Tester::Configuration.root) if ARGV.size == 0
23
+
24
+ ARGV.map do |f|
25
+ Tester::Configuration.root = File.expand_path(f)
26
+ $LOAD_PATH.unshift(Tester::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 Tester
4
+ class FeatureGenerator < Rails::Generators::Base
5
+ source_root File.join(File.dirname(__FILE__), 'templates')
6
+
7
+ desc <<-DESC
8
+ Description:
9
+ Sets up WebTester for your Rails project.
10
+ `rails generate tester: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 = "tester/features/#{@name}_spec.rb"
17
+ table_filename = "tester/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 Tester
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.join(File.dirname(__FILE__), 'templates')
6
+
7
+ desc <<-DESC
8
+ Description:
9
+ Sets up WebTester for your Rails project.
10
+ `rails generate tester:install`
11
+ DESC
12
+
13
+ def manifest
14
+ empty_directory 'tester/features'
15
+ empty_directory 'tester/tables'
16
+ copy_file 'tester.yml', 'config/tester.yml'
17
+ copy_file 'helper.rb', 'tester/helper.rb'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ feature "<%= @const_name %>" do
2
+ scenario "Scenario name" do
3
+ true.must_equal true
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'tester.rb')
@@ -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 'tester/configuration'
7
+ require 'tester/parse'
8
+ require 'tester/table'
9
+
10
+ Capybara.default_driver = :selenium
11
+ MiniTest::Unit.autorun
12
+
13
+ module Tester
14
+ def self.should_run_type?(types)
15
+ return true if Tester::Configuration.types.nil?
16
+ return false if types.nil?
17
+ types = types.to_a.map(&:to_s)
18
+ (types - Tester::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 Tester.should_run_type?(opts[:type])
28
+ Tester::Configuration.load_setting_for_types(opts[:type])
29
+ test_file = File.expand_path(caller[0].sub(/:.*$/,''))
30
+
31
+ it desc do
32
+ data_table = Tester::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 Tester.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
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ module Tester
4
+ class Configuration
5
+ class << self
6
+ attr_accessor :types, :root
7
+
8
+ def root
9
+ test_path = File.expand_path('tester')
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, 'tester.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,6 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'parse', '*.rb')].each { |f| require f }
2
+
3
+ module Tester
4
+ module Parse
5
+ end
6
+ end
@@ -0,0 +1,79 @@
1
+ module Tester
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(Tester::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
+ #{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
@@ -0,0 +1,11 @@
1
+ module Tester
2
+ class Table
3
+ def self.[] test_file, name
4
+ parse_format = Tester::Configuration.config['table_format'] || 'plain_text'
5
+ table_file = test_file.sub(/_spec\.rb$/,'').sub(/^#{Tester::Configuration.root}\/features\//,'')
6
+ ## constantize: plain_text => PlainText
7
+ parse_format = parse_format.capitalize.gsub(/_(\w)/) { $1.capitalize }
8
+ return Tester::Parse.const_get(parse_format)[table_file, name.strip]
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protester
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 3
10
+ version: 0.1.3
11
+ platform: ruby
12
+ authors:
13
+ - Jinzhu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-09 00:00:00 +08:00
19
+ default_executable: webtester
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 tester
50
+ email: wosmvp@gmail.com
51
+ executables:
52
+ - webtester
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ - TODO
59
+ files:
60
+ - lib/generators/tester/feature_generator.rb
61
+ - lib/generators/tester/install_generator.rb
62
+ - lib/generators/tester/templates/feature_spec.rb
63
+ - lib/generators/tester/templates/helper.rb
64
+ - lib/protester.rb
65
+ - lib/tester.rb
66
+ - lib/tester/configuration.rb
67
+ - lib/tester/parse.rb
68
+ - lib/tester/parse/plain_text.rb
69
+ - lib/tester/table.rb
70
+ - LICENSE
71
+ - README.rdoc
72
+ - TODO
73
+ - bin/webtester
74
+ has_rdoc: true
75
+ homepage: http://github.com/jinzhu/protester
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: your trusty, tireless tester
108
+ test_files: []
109
+