Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

playing with linebreaks in generated method names to make stuff easie…

…r to read
  • Loading branch information...
commit 81e0833bcf5c1b3e68b9542c54c42f170e44c308 1 parent 1b2a28e
@svenfuchs authored
View
6 lib/with.rb
@@ -17,7 +17,7 @@ def with_common(*names)
end
def describe(name, &block)
- context = Context.build(*with_common + [name], &block).first
+ context = Context.build(name, *with_common, &block).first
context.compile(self)
context
end
@@ -45,4 +45,6 @@ def aspect?(aspect)
def it(name, &block)
yield
end
-end
+end
+
+Test::Unit::TestCase.send :include, With
View
8 lib/with/context.rb
@@ -77,10 +77,10 @@ def generate_test_method_name(context)
contexts = context.parents << context
assertions = context.calls(:assertion)
- name = "test_#{context.object_id}_#{contexts.shift.name}_"
- name += contexts.map { |c| "with_#{c.name}_" }.join('and_')
- name += assertions.map { |a| "it_#{a.name}_" }.join('and_')
- name.gsub(/\W/, '_').gsub('it_it_', 'it_').gsub('__', '_').gsub('__', '_').gsub(/"|(_$)/, '')
+ name = "test_##{context.object_id}\n#{contexts.shift.name}"
+ name += contexts.map { |c| "\nwith #{c.name} " }.join("and")
+ name += assertions.map { |a| "\nit #{a.name} " }.join("and")
+ name.gsub('_', ' ').gsub(' ', ' ').gsub('it it', 'it') #.gsub('__', '_').gsub('__', '_').gsub(/"|(_$)/, '')
end
end
end
View
17 test/context_compile_test.rb
@@ -8,7 +8,7 @@ def setup
def call(context)
context.compile(Target)
target = Target.new
-
+
target.methods.select{|m| m =~ /^test_/ }.sort.reverse.inject([]) do |called, method|
target.send(method)
called << target.called.dup
@@ -83,7 +83,7 @@ def test_compile
def test_compile_with_conditions
collector = lambda { (@called ||= []) << @_with_current_context }
-
+
With.share(:shared, 'shared_1') { before 'shared_1_before', &collector }
With.share(:shared, 'shared_2') { before 'shared_2_before', &collector }
@@ -102,4 +102,17 @@ def test_compile_with_conditions
assert_equal expected, call(context)
end
+
+ # def test_compile_shared_backtrace
+ # collector = lambda { @trace = caller; break! }
+ # With.share(:shared, 'shared') { before 'shared_before', &collector }
+ # context = With::Context.build('foo', :shared){}.first
+ # context.compile(Target)
+ # target = Target.new
+ #
+ # target.methods.select{|m| m =~ /^test_/ }.sort.reverse.inject([]) do |called, method|
+ # target.send(method)
+ # target.instance_variable_get(:@trace).each { |line| puts line }
+ # end
+ # end
end
View
4 test/context_structure_test.rb
@@ -106,7 +106,7 @@ def test_context_with_common_parents
Target.with_common :common
Target.share(:common){}
names = context_names [Target.describe('bar'){ with 'foo' }]
- assert_equal [[[:common, 'bar', 'foo']]], names
+ assert_equal [[['bar', :common, 'foo']]], names
end
def test_different_nested_contexts_with_common_shared_parent
@@ -116,6 +116,6 @@ def test_different_nested_contexts_with_common_shared_parent
with(:bar){ assertion('renders :edit'){} }
end.first
assert_equal 'renders :new', context.children[0].calls(:assertion)[0].name
- assert_equal 'renders :edit', context.children[1].calls(:assertion)[1].name
+ assert_equal 'renders :edit', context.children[1].calls(:assertion)[0].name
end
end
View
10 test/demo_test.rb
@@ -52,11 +52,11 @@ def test_something
#puts; puts Target.instance_methods.grep(/^test_/).join(", \n ")
assert_equal 5, methods.count
- expected = [[[:caching, :observers, 'POST to :create', :login_as_admin, :valid_article_params],
- [:caching, :observers, 'POST to :create', :login_as_admin, :invalid_article_params],
- [:caching, :observers, 'POST to :create', :login_as_admin, :invalid_article_params],
- [:caching, :observers, 'POST to :create', :login_as_user],
- [:caching, :observers, 'POST to :create', :no_login]]]
+ expected = [[['POST to :create', :caching, :observers, :login_as_admin, :valid_article_params],
+ ['POST to :create', :caching, :observers, :login_as_admin, :invalid_article_params],
+ ['POST to :create', :caching, :observers, :login_as_admin, :invalid_article_params],
+ ['POST to :create', :caching, :observers, :login_as_user],
+ ['POST to :create', :caching, :observers, :no_login]]]
assert_equal expected, context_names([context])
end
View
2  test/helper.rb
@@ -35,7 +35,7 @@ def context_names(contexts)
end
end
-class With
+module With
class Node
def inspect
$_INDENT ||= 0
Please sign in to comment.
Something went wrong with that request. Please try again.