Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted dsl from xing_user_story
- Loading branch information
0 parents
commit 3af1d45
Showing
9 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* | ||
/.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in filet.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'bundler/gem_tasks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "filet/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "filet" | ||
s.version = Filet::VERSION | ||
s.authors = ["Jorge Dias", "Jakub Godawa"] | ||
s.email = ["jorge.dias@xing.com", "jakub.godawa@xing.com"] | ||
s.homepage = "" | ||
s.summary = %q{Acceptance Testing framework for Test::Unit} | ||
s.description = %q{Extension for Test::Unit to have a Steak-like DSL for acceptance testing} | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Filet | ||
def rails? | ||
defined?(ActionController) | ||
end | ||
|
||
extend self | ||
end | ||
|
||
require "filet/version" | ||
require "filet/test_case" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Active Support extensions for Test::Unit::TestCase | ||
module Filet::Backport | ||
module Declarative | ||
def test(name, &block) | ||
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym | ||
defined = instance_method(test_name) rescue false | ||
raise "#{test_name} is already defined in #{self}" if defined | ||
if block_given? | ||
define_method(test_name, &block) | ||
else | ||
define_method(test_name) do | ||
flunk "No implementation provided for #{name}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'test/unit' | ||
require 'filet' | ||
require 'filet/backport' | ||
|
||
module Filet | ||
base_klass = Filet.rails? ? ActionController::IntegrationTest : Test::Unit::TestCase | ||
|
||
class TestCase < base_klass | ||
@@context_hook = nil | ||
|
||
extend Filet::Backport::Declarative unless Filet.rails? | ||
|
||
class << self | ||
attr_accessor :description | ||
|
||
alias :scenario :test | ||
|
||
def context(name, options = {}, &block) | ||
klass = create_class(name, self, &block) | ||
|
||
context_hook.call(klass, options) if context_hook | ||
|
||
klass | ||
end | ||
|
||
def background(&block) | ||
define_method(:setup, &block) | ||
end | ||
|
||
def teardown(&block) | ||
define_method(:teardown, &block) | ||
end | ||
|
||
def context_hook(&block) | ||
if block | ||
@@context_hook = block | ||
else | ||
@@context_hook | ||
end | ||
end | ||
|
||
def context_hook=(block) | ||
@@context_hook = block | ||
end | ||
end | ||
|
||
# Placeholder so test/unit ignores test cases without any tests. | ||
def default_test | ||
end | ||
|
||
end | ||
|
||
def feature(name, description, options = {}, &block) | ||
klass = create_class(name, Filet::TestCase, &block) | ||
klass.description = description | ||
klass | ||
end | ||
|
||
def create_class(name, superclass, &block) | ||
klass = Class.new(superclass, &block) | ||
name = name.gsub(/(^\d*|\W)/, ' ').lstrip | ||
klass_name = name.gsub(/(^[a-z]|\s+\w)/).each do |match| | ||
match.lstrip.upcase | ||
end | ||
|
||
superclass.const_set klass_name, klass | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Filet | ||
VERSION = "0.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
require 'test/unit' | ||
require 'filet/test_case' | ||
|
||
include Filet | ||
|
||
module Filet | ||
class TestCaseTest < Test::Unit::TestCase | ||
def test_feature_returns_filet_test_case | ||
klass = feature("feature name", "feature description lorem ipsum") | ||
assert_equal Filet::TestCase, klass.superclass | ||
assert_equal "Filet::TestCase::FeatureName", klass.name | ||
assert_equal "feature description lorem ipsum", klass.description | ||
end | ||
|
||
def test_context_returns_feature_subclass | ||
klass = nil | ||
feature("feature name", "description") do | ||
klass = context("acceptance criteria 1") | ||
end | ||
|
||
assert_match /FeatureName::AcceptanceCriteria1$/, klass.name | ||
assert_match /FeatureName$/, klass.superclass.name | ||
end | ||
|
||
def test_provides_a_hook_to_process_context_options | ||
Filet::TestCase.context_hook do |base, options| | ||
if options[:js] | ||
base.instance_variable_set("@js_option", true) | ||
end | ||
end | ||
|
||
klass = nil | ||
|
||
feature("feature name", "description") do | ||
klass = context("acceptance criteria js", :js => true) | ||
end | ||
|
||
assert klass.instance_variable_get("@js_option"), "hook is not used" | ||
|
||
Filet::TestCase.context_hook = nil | ||
end | ||
|
||
def test_class_nesting | ||
context_klass = context_klass = | ||
context_klass2 = context_klass2 = nil | ||
|
||
feature("feature name", "description") do | ||
context_klass = context("some context") do | ||
context_klass = context("the criteria") | ||
end | ||
|
||
context_klass2 = context("other context") do | ||
context_klass2 = context("the criteria") | ||
end | ||
end | ||
|
||
assert_not_equal context_klass.name, context_klass2.name | ||
assert_not_equal context_klass.name, context_klass2.name | ||
end | ||
|
||
def test_background_method | ||
klass = feature("feature name", "description") do | ||
background do | ||
klass.instance_variable_set("@setup_created", true) | ||
end | ||
end | ||
|
||
klass.new('default_test').setup | ||
assert klass.instance_variable_get('@setup_created') | ||
end | ||
|
||
def test_teardown_method | ||
klass = feature("feature name", "description") do | ||
teardown do | ||
klass.instance_variable_set("@teardown_created", true) | ||
end | ||
end | ||
|
||
klass.new('default_test').teardown | ||
assert klass.instance_variable_get('@teardown_created') | ||
end | ||
|
||
def test_scenario | ||
context_klass = nil | ||
|
||
klass = feature("feature name", "description") do | ||
scenario "Scenario description" | ||
|
||
context_klass = context "Grouping context" do | ||
scenario "Nested Scenario" | ||
end | ||
end | ||
|
||
assert klass.instance_methods.include?("test_Scenario_description") | ||
assert context_klass.instance_methods.include?("test_Nested_Scenario") | ||
end | ||
|
||
def teardown | ||
Filet::TestCase.send(:remove_const, :FeatureName) if defined?(Filet::TestCase::FeatureName) | ||
end | ||
end | ||
end |