filet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ /.rvmrc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in filet.gemspec
4
+ gemspec
5
+
6
+ gem 'ruby-debug'
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Jorge Dias, Jakub Godawa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/Readme.md ADDED
@@ -0,0 +1,39 @@
1
+ # Filet
2
+
3
+ Filet is a dsl for acceptance testing on top of Test::Unit.
4
+
5
+ ## Installation
6
+
7
+ gem install filet
8
+
9
+ ## Usage
10
+
11
+ To use filet just include in your test_helper
12
+
13
+ require 'filet'
14
+ include Filet
15
+
16
+ ## Hooks
17
+
18
+ We provide several hooks for options processing.
19
+
20
+ 1. Filet.feature_hook
21
+
22
+ This allows to process the options you pass for the feature
23
+
24
+ Filet.feature_hook do |base, options|
25
+ base.send(:include, Capybara)
26
+ end
27
+
28
+ 2. Filet.context_hook
29
+
30
+ This allows to process the options you pass for the context
31
+
32
+ Filet.context_hook do |base, options|
33
+ base.send(:include, SomeModule) if options[:js]
34
+ end
35
+
36
+ ## Acknowledgements
37
+
38
+ 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.
39
+ We also want to thank Luismi Cavallé for steak which was our inspiration to do this and all the great people that have made Testing so easy.
data/filet.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "filet/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "filet"
7
+ s.version = Filet::VERSION
8
+ s.authors = ["Jorge Dias", "Jakub Godawa"]
9
+ s.email = ["jorge@mrdias.com", "jakub.godawa@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Acceptance Testing framework for Test::Unit}
12
+ s.description = %q{Extension for Test::Unit to have a Steak-like DSL for acceptance testing}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ end
data/lib/filet.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Filet
2
+ def rails?
3
+ defined?(ActionController)
4
+ end
5
+
6
+ extend self
7
+ end
8
+
9
+ require "filet/version"
10
+ require "filet/test_case"
@@ -0,0 +1,17 @@
1
+ # Active Support extensions for Test::Unit::TestCase
2
+ module Filet::Backport
3
+ module Declarative
4
+ def test(name, &block)
5
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
6
+ defined = instance_method(test_name) rescue false
7
+ raise "#{test_name} is already defined in #{self}" if defined
8
+ if block_given?
9
+ define_method(test_name, &block)
10
+ else
11
+ define_method(test_name) do
12
+ flunk "No implementation provided for #{name}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ module Filet::Hooks
2
+ def self.extended(base)
3
+ base.class_eval do
4
+ @@context_hook = nil
5
+ @@feature_hook = nil
6
+ end
7
+ end
8
+
9
+ # TODO: Abstract the hook creation if we need another one
10
+ def feature_hook(&block)
11
+ if block
12
+ @@feature_hook = block
13
+ else
14
+ @@feature_hook
15
+ end
16
+ end
17
+
18
+ def feature_hook=(block)
19
+ @@feature_hook = block
20
+ end
21
+
22
+ def context_hook(&block)
23
+ if block
24
+ @@context_hook = block
25
+ else
26
+ @@context_hook
27
+ end
28
+ end
29
+
30
+ def context_hook=(block)
31
+ @@context_hook = block
32
+ end
33
+ end
@@ -0,0 +1,60 @@
1
+ require 'test/unit'
2
+ require 'filet'
3
+ require 'filet/backport'
4
+ require 'filet/hooks'
5
+
6
+ module Filet
7
+ base_klass = Filet.rails? ? ActionController::IntegrationTest : Test::Unit::TestCase
8
+
9
+ class TestCase < base_klass
10
+
11
+ extend Filet::Hooks
12
+ extend Filet::Backport::Declarative unless Filet.rails?
13
+
14
+ class << self
15
+ attr_accessor :description
16
+
17
+ alias :scenario :test
18
+
19
+ def context(name, options = {}, &block)
20
+ klass = create_class(name, self, &block)
21
+
22
+ context_hook.call(klass, options) if context_hook
23
+
24
+ klass
25
+ end
26
+
27
+ def background(&block)
28
+ define_method(:setup, &block)
29
+ end
30
+
31
+ def teardown(&block)
32
+ define_method(:teardown, &block)
33
+ end
34
+
35
+ end
36
+
37
+ # Placeholder so test/unit ignores test cases without any tests.
38
+ def default_test
39
+ end
40
+
41
+ end
42
+
43
+ def feature(name, description, options = {}, &block)
44
+ klass = create_class(name, Filet::TestCase, &block)
45
+ klass.description = description
46
+
47
+ Filet::TestCase.feature_hook.call(klass, options) if Filet::TestCase.feature_hook
48
+ klass
49
+ end
50
+
51
+ def create_class(name, superclass, &block)
52
+ klass = Class.new(superclass, &block)
53
+ name = name.gsub(/(^\d*|\W)/, ' ').lstrip
54
+ klass_name = name.gsub(/(^[a-z]|\s+\w)/).each do |match|
55
+ match.lstrip.upcase
56
+ end
57
+
58
+ superclass.const_set klass_name, klass
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Filet
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,116 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'test/unit'
4
+ require 'filet/test_case'
5
+
6
+ include Filet
7
+
8
+ module Filet
9
+ class TestCaseTest < Test::Unit::TestCase
10
+ def test_feature_returns_filet_test_case
11
+ klass = feature("feature name", "feature description lorem ipsum")
12
+ assert_equal Filet::TestCase, klass.superclass
13
+ assert_equal "Filet::TestCase::FeatureName", klass.name
14
+ assert_equal "feature description lorem ipsum", klass.description
15
+ end
16
+
17
+ def test_context_returns_feature_subclass
18
+ klass = nil
19
+ feature("feature name", "description") do
20
+ klass = context("acceptance criteria 1")
21
+ end
22
+
23
+ assert_match /FeatureName::AcceptanceCriteria1$/, klass.name
24
+ assert_match /FeatureName$/, klass.superclass.name
25
+ end
26
+
27
+ def test_provides_a_hook_to_process_feature_options
28
+ Filet::TestCase.feature_hook do |base, options|
29
+ base.instance_variable_set("@feature_hook_on", true)
30
+ end
31
+
32
+ klass = feature("feature name", "description")
33
+
34
+ assert klass.instance_variable_get("@feature_hook_on"), "hook is not used"
35
+
36
+ Filet::TestCase.feature_hook = nil
37
+ end
38
+
39
+ def test_provides_a_hook_to_process_context_options
40
+ Filet::TestCase.context_hook do |base, options|
41
+ if options[:js]
42
+ base.instance_variable_set("@js_option", true)
43
+ end
44
+ end
45
+
46
+ klass = nil
47
+
48
+ feature("feature name", "description") do
49
+ klass = context("acceptance criteria js", :js => true)
50
+ end
51
+
52
+ assert klass.instance_variable_get("@js_option"), "hook is not used"
53
+
54
+ Filet::TestCase.context_hook = nil
55
+ end
56
+
57
+ def test_class_nesting
58
+ context_klass = context_klass =
59
+ context_klass2 = context_klass2 = nil
60
+
61
+ feature("feature name", "description") do
62
+ context_klass = context("some context") do
63
+ context_klass = context("the criteria")
64
+ end
65
+
66
+ context_klass2 = context("other context") do
67
+ context_klass2 = context("the criteria")
68
+ end
69
+ end
70
+
71
+ assert_not_equal context_klass.name, context_klass2.name
72
+ assert_not_equal context_klass.name, context_klass2.name
73
+ end
74
+
75
+ def test_background_method
76
+ klass = feature("feature name", "description") do
77
+ background do
78
+ klass.instance_variable_set("@setup_created", true)
79
+ end
80
+ end
81
+
82
+ klass.new('default_test').setup
83
+ assert klass.instance_variable_get('@setup_created')
84
+ end
85
+
86
+ def test_teardown_method
87
+ klass = feature("feature name", "description") do
88
+ teardown do
89
+ klass.instance_variable_set("@teardown_created", true)
90
+ end
91
+ end
92
+
93
+ klass.new('default_test').teardown
94
+ assert klass.instance_variable_get('@teardown_created')
95
+ end
96
+
97
+ def test_scenario
98
+ context_klass = nil
99
+
100
+ klass = feature("feature name", "description") do
101
+ scenario "Scenario description"
102
+
103
+ context_klass = context "Grouping context" do
104
+ scenario "Nested Scenario"
105
+ end
106
+ end
107
+
108
+ assert klass.instance_methods.include?("test_Scenario_description")
109
+ assert context_klass.instance_methods.include?("test_Nested_Scenario")
110
+ end
111
+
112
+ def teardown
113
+ Filet::TestCase.send(:remove_const, :FeatureName) if defined?(Filet::TestCase::FeatureName)
114
+ end
115
+ end
116
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Dias
9
+ - Jakub Godawa
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-07-22 00:00:00.000000000 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+ description: Extension for Test::Unit to have a Steak-like DSL for acceptance testing
17
+ email:
18
+ - jorge@mrdias.com
19
+ - jakub.godawa@gmail.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - .gitignore
25
+ - Gemfile
26
+ - LICENSE
27
+ - Rakefile
28
+ - Readme.md
29
+ - filet.gemspec
30
+ - lib/filet.rb
31
+ - lib/filet/backport.rb
32
+ - lib/filet/hooks.rb
33
+ - lib/filet/test_case.rb
34
+ - lib/filet/version.rb
35
+ - test/filet/test_case_test.rb
36
+ has_rdoc: true
37
+ homepage: ''
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.6.2
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Acceptance Testing framework for Test::Unit
61
+ test_files:
62
+ - test/filet/test_case_test.rb