filet 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/Gemfile +1 -2
- data/Rakefile +1 -1
- data/Readme.md +64 -24
- data/filet.gemspec +4 -0
- data/lib/filet.rb +6 -6
- data/lib/filet/hooks.rb +26 -22
- data/lib/filet/integration.rb +27 -0
- data/lib/filet/test_case.rb +14 -13
- data/lib/filet/version.rb +1 -1
- data/test/filet/active_support_integration_test.rb +12 -0
- data/test/filet/test_case_test.rb +28 -14
- data/test/test_helper.rb +7 -0
- metadata +89 -23
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/Readme.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Filet is a dsl for acceptance testing on top of Test::Unit.
|
4
4
|
|
5
|
+
## Why filet?
|
6
|
+
|
7
|
+
Filet is framework agnostic, it can be used with plain Ruby or it can integrate with Rails or any framework of your choice, you can use it with Capybara, Webrat or any other tools you like.
|
8
|
+
Filet has no dependencies.
|
9
|
+
Filet is Test:Unit but pretty!
|
10
|
+
|
5
11
|
## Installation
|
6
12
|
|
7
13
|
gem install filet
|
@@ -15,30 +21,6 @@ require 'filet'
|
|
15
21
|
include Filet
|
16
22
|
```
|
17
23
|
|
18
|
-
## Hooks
|
19
|
-
|
20
|
-
We provide several hooks for options processing.
|
21
|
-
|
22
|
-
1. Filet.feature_hook
|
23
|
-
|
24
|
-
This allows to process the options you pass for the feature
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
Filet.feature_hook do |base, options|
|
28
|
-
base.send(:include, Capybara)
|
29
|
-
end
|
30
|
-
```
|
31
|
-
|
32
|
-
2. Filet.context_hook
|
33
|
-
|
34
|
-
This allows to process the options you pass for the context
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
Filet.context_hook do |base, options|
|
38
|
-
base.send(:include, SomeModule) if options[:js]
|
39
|
-
end
|
40
|
-
```
|
41
|
-
|
42
24
|
## Example
|
43
25
|
|
44
26
|
```ruby
|
@@ -48,11 +30,20 @@ feature 'Creating a post', %{
|
|
48
30
|
In order to show it to people
|
49
31
|
} do
|
50
32
|
|
33
|
+
background do
|
34
|
+
# setup data
|
35
|
+
end
|
36
|
+
|
51
37
|
scenario 'Everything goes fine after a submit' do
|
52
38
|
# test code
|
53
39
|
end
|
54
40
|
|
55
41
|
context 'Something goes wrong', :js => true do
|
42
|
+
|
43
|
+
background do
|
44
|
+
# setup more data
|
45
|
+
end
|
46
|
+
|
56
47
|
scenario 'my keyboard stopped working' do
|
57
48
|
# test code
|
58
49
|
end
|
@@ -60,9 +51,58 @@ feature 'Creating a post', %{
|
|
60
51
|
scenario 'I forgot to fill up the form' do
|
61
52
|
# test code
|
62
53
|
end
|
54
|
+
|
55
|
+
teardown do
|
56
|
+
# clean up
|
57
|
+
end
|
63
58
|
end
|
64
59
|
end
|
65
60
|
```
|
61
|
+
|
62
|
+
## Hooks
|
63
|
+
|
64
|
+
We provide several hooks for options processing.
|
65
|
+
|
66
|
+
1. Filet.feature_hook
|
67
|
+
|
68
|
+
This allows to process the options you pass for the feature
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Filet.feature_hook do |base, options|
|
72
|
+
base.send(:include, Capybara)
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
2. Filet.context_hook
|
77
|
+
|
78
|
+
This allows to process the options you pass for the context
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Filet.context_hook do |base, options|
|
82
|
+
base.send(:include, SomeModule) if options[:js]
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
3. Filet.base_klass
|
87
|
+
|
88
|
+
This allows you to define the base_klass of your tests. It tries to make a guess based on your environment and integrates with Rails 3 and Rails 2. The default is Test::Unit::TestCase.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
Filet.base_klass = ActiveSupport::TestCase
|
92
|
+
```
|
93
|
+
|
94
|
+
*NOTE*: This hook must be initialized before you include the Filet module
|
95
|
+
|
96
|
+
## Compatibility
|
97
|
+
|
98
|
+
Filet supports and is tested against ruby 1.8.7, 1.9.2, jruby-1.6.2 and rubinius-1.2.4
|
99
|
+
|
100
|
+
[![Build Status](http://travis-ci.org/xing/filet.png)](http://travis-ci.org/xing/filet)
|
101
|
+
|
102
|
+
### Rails Integration
|
103
|
+
|
104
|
+
It tries to make a guess based on your environment and integrates with Rails 3 and Rails 2. We recommend that you place your tests inside the test/integration folder.
|
105
|
+
|
66
106
|
## Acknowledgements
|
67
107
|
|
68
108
|
We'd like to thank our employer XING AG for letting us work on this project as part of our innovation time and releasing it as open source.
|
data/filet.gemspec
CHANGED
@@ -11,6 +11,10 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{Acceptance Testing framework for Test::Unit}
|
12
12
|
s.description = %q{Extension for Test::Unit to have a Steak-like DSL for acceptance testing}
|
13
13
|
|
14
|
+
s.add_development_dependency "rake"
|
15
|
+
s.add_development_dependency "activesupport"
|
16
|
+
s.add_development_dependency "i18n"
|
17
|
+
|
14
18
|
s.files = `git ls-files`.split("\n")
|
15
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/lib/filet.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
require "filet/version"
|
2
|
+
require "filet/hooks"
|
3
|
+
require "filet/integration"
|
4
|
+
|
1
5
|
module Filet
|
2
|
-
def
|
3
|
-
|
6
|
+
def self.included(base)
|
7
|
+
require "filet/test_case"
|
4
8
|
end
|
5
|
-
|
6
|
-
extend self
|
7
9
|
end
|
8
10
|
|
9
|
-
require "filet/version"
|
10
|
-
require "filet/test_case"
|
data/lib/filet/hooks.rb
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
-
module Filet
|
2
|
-
|
3
|
-
base
|
4
|
-
|
5
|
-
|
1
|
+
module Filet
|
2
|
+
module Hooks
|
3
|
+
def self.extended(base)
|
4
|
+
base.class_eval do
|
5
|
+
@@context_hook = nil
|
6
|
+
@@feature_hook = nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# TODO: Abstract the hook creation if we need another one
|
11
|
+
def feature_hook(&block)
|
12
|
+
if block
|
13
|
+
@@feature_hook = block
|
14
|
+
else
|
15
|
+
@@feature_hook
|
16
|
+
end
|
6
17
|
end
|
7
|
-
end
|
8
18
|
|
9
|
-
|
10
|
-
def feature_hook(&block)
|
11
|
-
if block
|
19
|
+
def feature_hook=(block)
|
12
20
|
@@feature_hook = block
|
13
|
-
else
|
14
|
-
@@feature_hook
|
15
21
|
end
|
16
|
-
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
def context_hook(&block)
|
24
|
+
if block
|
25
|
+
@@context_hook = block
|
26
|
+
else
|
27
|
+
@@context_hook
|
28
|
+
end
|
29
|
+
end
|
21
30
|
|
22
|
-
|
23
|
-
if block
|
31
|
+
def context_hook=(block)
|
24
32
|
@@context_hook = block
|
25
|
-
else
|
26
|
-
@@context_hook
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
|
-
|
31
|
-
@@context_hook = block
|
32
|
-
end
|
36
|
+
extend Hooks
|
33
37
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Filet
|
2
|
+
module Integration
|
3
|
+
def base_klass
|
4
|
+
@@filet_base_klass ||=
|
5
|
+
# rails 3
|
6
|
+
if defined?(ActionDispatch)
|
7
|
+
require 'action_dispatch/testing/integration'
|
8
|
+
ActionDispatch::IntegrationTest
|
9
|
+
# rails 2
|
10
|
+
elsif defined?(ActionController)
|
11
|
+
ActionController::IntegrationTest
|
12
|
+
elsif defined?(ActiveSupport)
|
13
|
+
require 'active_support/test_case'
|
14
|
+
ActiveSupport::TestCase
|
15
|
+
else
|
16
|
+
require 'test/unit/testcase'
|
17
|
+
Test::Unit::TestCase
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_klass=(klass)
|
22
|
+
@@filet_base_klass = klass
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
extend Integration
|
27
|
+
end
|
data/lib/filet/test_case.rb
CHANGED
@@ -1,15 +1,9 @@
|
|
1
|
-
require 'test/unit'
|
2
1
|
require 'filet'
|
3
2
|
require 'filet/backport'
|
4
|
-
require 'filet/hooks'
|
5
3
|
|
6
4
|
module Filet
|
7
|
-
|
8
|
-
|
9
|
-
class TestCase < base_klass
|
10
|
-
|
11
|
-
extend Filet::Hooks
|
12
|
-
extend Filet::Backport::Declarative unless Filet.rails?
|
5
|
+
class TestCase < Filet.base_klass
|
6
|
+
extend Filet::Backport::Declarative unless respond_to?(:test)
|
13
7
|
|
14
8
|
class << self
|
15
9
|
attr_accessor :description
|
@@ -19,17 +13,23 @@ module Filet
|
|
19
13
|
def context(name, options = {}, &block)
|
20
14
|
klass = create_class(name, self, &block)
|
21
15
|
|
22
|
-
context_hook.call(klass, options) if context_hook
|
16
|
+
Filet.context_hook.call(klass, options) if Filet.context_hook
|
23
17
|
|
24
18
|
klass
|
25
19
|
end
|
26
20
|
|
27
21
|
def background(&block)
|
28
|
-
define_method(:setup
|
22
|
+
define_method(:setup) do
|
23
|
+
super()
|
24
|
+
instance_eval(&block)
|
25
|
+
end
|
29
26
|
end
|
30
27
|
|
31
28
|
def teardown(&block)
|
32
|
-
define_method(:teardown
|
29
|
+
define_method(:teardown) do
|
30
|
+
instance_eval(&block)
|
31
|
+
super()
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -37,17 +37,18 @@ module Filet
|
|
37
37
|
# Placeholder so test/unit ignores test cases without any tests.
|
38
38
|
def default_test
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
41
|
|
43
42
|
def feature(name, description, options = {}, &block)
|
44
43
|
klass = create_class(name, Filet::TestCase, &block)
|
45
44
|
klass.description = description
|
46
45
|
|
47
|
-
Filet
|
46
|
+
Filet.feature_hook.call(klass, options) if Filet.feature_hook
|
48
47
|
klass
|
49
48
|
end
|
50
49
|
|
50
|
+
private
|
51
|
+
|
51
52
|
def create_class(name, superclass, &block)
|
52
53
|
klass = Class.new(superclass)
|
53
54
|
name = name.gsub(/(^\d*|\W)/, ' ').lstrip
|
data/lib/filet/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'active_support/test_case'
|
3
|
+
|
4
|
+
class ActiveSupportIntegrationTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Filet.base_klass = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_base_klass
|
10
|
+
assert_equal ActiveSupport::TestCase, Filet.base_klass
|
11
|
+
end
|
12
|
+
end
|
@@ -1,7 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'filet/test_case'
|
3
|
-
|
4
|
-
include Filet
|
1
|
+
require 'test_helper'
|
5
2
|
|
6
3
|
module Filet
|
7
4
|
class TestCaseTest < Test::Unit::TestCase
|
@@ -23,7 +20,7 @@ module Filet
|
|
23
20
|
end
|
24
21
|
|
25
22
|
def test_provides_a_hook_to_process_feature_options
|
26
|
-
Filet
|
23
|
+
Filet.feature_hook do |base, options|
|
27
24
|
base.instance_variable_set("@feature_hook_on", true)
|
28
25
|
end
|
29
26
|
|
@@ -31,11 +28,11 @@ module Filet
|
|
31
28
|
|
32
29
|
assert klass.instance_variable_get("@feature_hook_on"), "hook is not used"
|
33
30
|
|
34
|
-
Filet
|
31
|
+
Filet.feature_hook = nil
|
35
32
|
end
|
36
33
|
|
37
34
|
def test_provides_a_hook_to_process_context_options
|
38
|
-
Filet
|
35
|
+
Filet.context_hook do |base, options|
|
39
36
|
if options[:js]
|
40
37
|
base.instance_variable_set("@js_option", true)
|
41
38
|
end
|
@@ -49,25 +46,23 @@ module Filet
|
|
49
46
|
|
50
47
|
assert klass.instance_variable_get("@js_option"), "hook is not used"
|
51
48
|
|
52
|
-
Filet
|
49
|
+
Filet.context_hook = nil
|
53
50
|
end
|
54
51
|
|
55
|
-
def
|
56
|
-
context_klass =
|
57
|
-
context_klass2 = context_klass2 = nil
|
52
|
+
def test_class_nesting_names
|
53
|
+
context_klass = context_klass2 = nil
|
58
54
|
|
59
55
|
feature("feature name", "description") do
|
60
|
-
|
56
|
+
context("some context") do
|
61
57
|
context_klass = context("the criteria")
|
62
58
|
end
|
63
59
|
|
64
|
-
|
60
|
+
context("other context") do
|
65
61
|
context_klass2 = context("the criteria")
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
69
65
|
assert_not_equal context_klass.name, context_klass2.name
|
70
|
-
assert_not_equal context_klass.name, context_klass2.name
|
71
66
|
end
|
72
67
|
|
73
68
|
def test_background_method
|
@@ -81,6 +76,25 @@ module Filet
|
|
81
76
|
assert klass.instance_variable_get('@setup_created')
|
82
77
|
end
|
83
78
|
|
79
|
+
def test_nested_backgrounds
|
80
|
+
feature("feature name", "description") do
|
81
|
+
background do
|
82
|
+
instance_variable_set("@feature_background", true)
|
83
|
+
end
|
84
|
+
context "nested" do
|
85
|
+
background do
|
86
|
+
instance_variable_set("@nested_background", true)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
test = Filet::TestCase::FeatureName::Nested.new('default_test')
|
92
|
+
test.setup
|
93
|
+
|
94
|
+
assert test.instance_variable_get("@feature_background")
|
95
|
+
assert test.instance_variable_get("@nested_background")
|
96
|
+
end
|
97
|
+
|
84
98
|
def test_teardown_method
|
85
99
|
klass = feature("feature name", "description") do
|
86
100
|
teardown do
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,27 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: filet
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Jorge Dias
|
9
14
|
- Jakub Godawa
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
|
-
|
18
|
+
|
19
|
+
date: 2011-08-24 00:00:00 +02:00
|
14
20
|
default_executable:
|
15
|
-
dependencies:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rake
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: i18n
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
16
64
|
description: Extension for Test::Unit to have a Steak-like DSL for acceptance testing
|
17
|
-
email:
|
65
|
+
email:
|
18
66
|
- jorge@mrdias.com
|
19
67
|
- jakub.godawa@gmail.com
|
20
68
|
executables: []
|
69
|
+
|
21
70
|
extensions: []
|
71
|
+
|
22
72
|
extra_rdoc_files: []
|
23
|
-
|
73
|
+
|
74
|
+
files:
|
24
75
|
- .gitignore
|
76
|
+
- .travis.yml
|
25
77
|
- Gemfile
|
26
78
|
- LICENSE
|
27
79
|
- Rakefile
|
@@ -30,33 +82,47 @@ files:
|
|
30
82
|
- lib/filet.rb
|
31
83
|
- lib/filet/backport.rb
|
32
84
|
- lib/filet/hooks.rb
|
85
|
+
- lib/filet/integration.rb
|
33
86
|
- lib/filet/test_case.rb
|
34
87
|
- lib/filet/version.rb
|
88
|
+
- test/filet/active_support_integration_test.rb
|
35
89
|
- test/filet/test_case_test.rb
|
90
|
+
- test/test_helper.rb
|
36
91
|
has_rdoc: true
|
37
|
-
homepage:
|
92
|
+
homepage: ""
|
38
93
|
licenses: []
|
94
|
+
|
39
95
|
post_install_message:
|
40
96
|
rdoc_options: []
|
41
|
-
|
97
|
+
|
98
|
+
require_paths:
|
42
99
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
101
|
none: false
|
45
|
-
requirements:
|
46
|
-
- -
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
|
49
|
-
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
110
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
55
118
|
requirements: []
|
119
|
+
|
56
120
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.
|
121
|
+
rubygems_version: 1.3.7
|
58
122
|
signing_key:
|
59
123
|
specification_version: 3
|
60
124
|
summary: Acceptance Testing framework for Test::Unit
|
61
|
-
test_files:
|
125
|
+
test_files:
|
126
|
+
- test/filet/active_support_integration_test.rb
|
62
127
|
- test/filet/test_case_test.rb
|
128
|
+
- test/test_helper.rb
|