coulda 0.6.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -95,3 +95,12 @@ Cleanup
95
95
  0.6.1
96
96
  -----
97
97
  - Requiring coulda automatcally loads coulda/tasks. No longer need to require 'coulda/tasks' to get the Rake task in your Rails app.
98
+
99
+ 0.6.2
100
+ -----
101
+ - Updated call method by name to use class methods so that they, and "macros", may universally be imported via 'extends SomeModule'
102
+
103
+ 0.6.3
104
+ -----
105
+ - Renamed #pending to #coulda_pending to avoid conflicts with Rails 3
106
+ - Failing test in this release as I stupidly began working on some new features in the master branch. Don't use the new features (they're not documented outside of the new tests) and you'll be fine. ;-)
data/LICENSE CHANGED
@@ -2,7 +2,7 @@ coulda
2
2
 
3
3
  MIT License
4
4
 
5
- Copyright (c) 2009, Evan David Light
5
+ Copyright (c) 2009, 2010, 2011 Evan David Light
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -8,8 +8,6 @@ require 'shoulda'
8
8
  # Test::Unit::UI::VERBOSE
9
9
  Rake::TestTask.new('test') do |t|
10
10
  t.libs << 'test'
11
- src_files = Dir.glob('src/**/*.rb')
12
- src_files.each { |f| puts f; require f[0...-3] }
13
11
  t.pattern = 'test/**/*_test.rb'
14
12
  t.verbose = true
15
13
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{coulda}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Evan David Light"]
12
- s.date = %q{2010-11-20}
12
+ s.date = %q{2010-12-23}
13
13
  s.description = %q{Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse}
14
14
  s.email = %q{evan@tiggerpalace.com}
15
15
  s.extra_rdoc_files = [
@@ -1,30 +1,44 @@
1
+ require 'test/unit'
2
+
3
+ require File.join(File.dirname(__FILE__), 'coulda', 'world')
4
+ require File.join(File.dirname(__FILE__), 'coulda', 'feature')
5
+ require File.join(File.dirname(__FILE__), 'coulda', 'scenario')
6
+ require File.join(File.dirname(__FILE__), 'coulda', 'pending')
7
+ require File.join(File.dirname(__FILE__), 'coulda', 'vendor', 'constantize')
8
+ require File.join(File.dirname(__FILE__), 'coulda', 'vendor', 'underscore')
9
+ require File.join(File.dirname(__FILE__), 'coulda', 'tasks')
10
+
1
11
  module Coulda
2
12
  SyntaxError = Class.new(StandardError)
3
- end
4
-
5
- require 'test/unit'
6
13
 
7
- require 'coulda/world'
8
- require 'coulda/feature'
9
- require 'coulda/scenario'
10
- require 'coulda/pending'
11
- require 'coulda/vendor/constantize'
12
- require 'coulda/vendor/underscore'
13
- require 'coulda/tasks'
14
+ def Tag(name)
15
+ @feature_tags ||= []
16
+ @feature_tags << name.to_s
17
+ end
14
18
 
15
- module Kernel
16
19
  # Factory method for Test::Unit::TestCase subclasses
17
20
  def Feature(name, opts = {}, &block)
21
+ process_command_line_tags
22
+
23
+ if @requested_tags && !@requested_tags.empty?
24
+ if @feature_tags.nil? || !@feature_tags.any? { |f_tag| @requested_tags.include? f_tag}
25
+ @feature_tags = nil
26
+ return
27
+ end
28
+ end
29
+ @feature_tags = nil
30
+
18
31
  test_class = Class.new(opts[:testcase_class] || Coulda.default_testcase_class || Test::Unit::TestCase)
32
+ World.register_feature(test_class, name)
33
+
19
34
  Coulda::assign_class_to_const test_class, name
20
35
  test_class.class_eval &block if block_given?
21
36
  test_class.assert_presence_of_intent
22
- World.register_feature(test_class, name)
37
+
38
+
23
39
  test_class
24
40
  end
25
- end
26
41
 
27
- module Coulda
28
42
  def self.default_testcase_class=(klass)
29
43
  unless klass.is_a?(Class) && klass.ancestors.include?(Test::Unit::TestCase)
30
44
  raise Exception, "Can only provide a Test::Unit::TestCase"
@@ -44,6 +58,16 @@ module Coulda
44
58
  titleized_underscored_name = base_name.super_custom_underscore.gsub(/\b('?[a-z])/) { $1.upcase }
45
59
  Object.const_set(titleized_underscored_name, test_class)
46
60
  end
61
+
62
+ def process_command_line_tags
63
+ unless @processed_cmd_line_args
64
+ @processed_cmd_line_args = true
65
+ tags = ARGV.inject([]) { |m, a| m << a if a =~ /^tags=/; m }
66
+ @requested_tags = tags.map { |t| t.split("=")[1].split(",") }.flatten
67
+ end
68
+ end
47
69
  end
48
70
 
49
71
  include ::Coulda
72
+
73
+
@@ -34,7 +34,7 @@ module Test
34
34
  step = block
35
35
  end
36
36
  caller[0] =~ (/(.*):(.*)(:in)?/)
37
- stmt = { :type => :#{stmt}, :text => text, :block => step, :file => $1, :line => $2 }
37
+ stmt = { :type => :#{stmt}, :text => text, :block => step, :file => $1, :line => $2, :scenario => current_scenario }
38
38
  if text.is_a? Symbol
39
39
  stmt[:method] = text
40
40
  end
@@ -43,6 +43,9 @@ module Test
43
43
  HERE
44
44
  end
45
45
 
46
+ def Tag(name)
47
+ end
48
+
46
49
  # Creates a Scenario instance and adds it to the Feature
47
50
  def self.Scenario(scenario_name, &block)
48
51
  @scenarios ||=[]
@@ -2,23 +2,50 @@ module Test
2
2
  module Unit
3
3
  class TestCase
4
4
  @@pending_cases = []
5
- @@at_exit = false
5
+ @@error_contexts = []
6
+ @@pending_at_exit = false
7
+ @@exception_at_exit = false
6
8
 
7
9
  # Loosely based upon Jeremy McAnally's pending
8
10
 
9
- def pending(scenario, statement)
10
- @@pending_cases << [scenario, statement]
11
+ def coulda_pending(txt)
11
12
  print "P"
13
+ @@pending_cases << txt
12
14
 
13
15
  @@at_exit ||= begin
14
16
  at_exit do
15
17
  puts "\nPending Cases:"
16
- @@pending_cases.each do |scenario, stmt|
17
- puts "#{stmt[:file]}:#{stmt[:line]}: Scenario '#{scenario.name}': #{stmt[:type]} '#{stmt[:text]}'"
18
+ @@pending_cases.each do |msg|
19
+ puts msg
18
20
  end
19
21
  end
20
22
  end
21
23
  end
24
+
25
+ def handle_exception(e, params = {})
26
+ stmt = params[:for_statement]
27
+
28
+ print "E"
29
+ @@error_contexts << params.merge(:exception => e)
30
+
31
+ @@exception_at_exit ||= begin
32
+ at_exit do
33
+ puts
34
+ puts "Exceptions"
35
+ puts "----------"
36
+
37
+ @@error_contexts.each_with_index do |ctx, i|
38
+ puts
39
+ puts "(#{i+1}) Feature: #{stmt[:scenario].feature.name}"
40
+ puts "Scenario: #{stmt[:scenario].name}"
41
+ puts "#{stmt[:type]} '#{stmt[:text]}'"
42
+ puts "In #{stmt[:file]} on line #{stmt[:line]}"
43
+ puts e.backtrace
44
+ end
45
+ end
46
+ end
47
+
48
+ end
22
49
  end
23
50
  end
24
51
  end
@@ -16,23 +16,28 @@ module Coulda
16
16
  def pending?
17
17
  statements.empty? || has_pending_statements?
18
18
  end
19
+
20
+ def feature
21
+ @my_feature
22
+ end
19
23
 
20
24
  private
21
25
 
22
26
  def create_and_provision_test_method_using(&block)
23
27
  collect_scenario_statements_from &block
24
28
  define_test_method_using do
25
- self.class.current_scenario.statements.each do |stmt|
29
+ scenario = self.class.current_scenario
30
+ scenario.statements.each do |stmt|
26
31
  if stmt[:method]
27
32
  if stmt[:block]
28
33
  raise Exception.new "Passing a block to a method called-by-name is currently unhandle"
29
34
  else
30
- self.__send__(stmt[:method])
35
+ self.class.__send__(stmt[:method])
31
36
  end
32
37
  elsif stmt[:block]
33
38
  self.instance_eval &(stmt[:block])
34
39
  else
35
- pending self.class.current_scenario, stmt
40
+ coulda_pending "#{stmt[:file]}:#{stmt[:line]}: Scenario '#{scenario.name}': #{stmt[:type]} '#{stmt[:text]}'"
36
41
  break
37
42
  end
38
43
  end
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+
3
+ namespace :coulda do
4
+ desc "Execute tagged tests only"
5
+ task :tagged_tests, :tag do |task, tag|
6
+ ARGV << "tags=#{tag["tag"]}"
7
+
8
+ $LOAD_PATH.unshift("test")
9
+
10
+ require 'test/unit'
11
+
12
+ test_files = Dir.glob(File.join('test', '**', '*_test.rb'))
13
+ test_files.each do |file|
14
+ require file
15
+ end
16
+ end
17
+ end
@@ -17,11 +17,3 @@ def run_feature(feature)
17
17
  end
18
18
  result
19
19
  end
20
-
21
- def pendings_are_errors
22
- Feature.class_eval do
23
- def pending(*args)
24
- raise Exception.new
25
- end
26
- end
27
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coulda
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Evan David Light
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-20 00:00:00 -05:00
18
+ date: 2010-12-23 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -45,8 +45,8 @@ files:
45
45
  - LICENSE
46
46
  - Rakefile
47
47
  - README.rdoc
48
- - VERSION
49
48
  - lib/tasks/print_features.rake
49
+ - lib/tasks/tagged_tests.rake
50
50
  - test/feature_test.rb
51
51
  - test/scenario_test.rb
52
52
  - test/test_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.3