0
require File.join(File.dirname(__FILE__), '..', 'test_helper')
0
class ShouldTest < Test::Unit::TestCase # :nodoc:
0
+ should "be able to define a should statement outside of a context" do
0
+ should "see the name of my class as ShouldTest" do
0
+ assert_equal "ShouldTest", self.class.name
0
+ def self.should_see_class_methods
0
+ should "be able to see class methods" do
0
+ def self.should_see_a_context_block_like_a_Test_Unit_class
0
+ should "see a context block as a Test::Unit class" do
0
+ assert_equal "ShouldTest", self.class.name
0
+ def self.should_see_blah
0
+ should "see @blah through a macro" do
0
+ def self.should_not_see_blah
0
+ should "not see @blah through a macro" do
0
+ def self.should_be_able_to_make_context_macros(prefix = nil)
0
+ should "have the tests named correctly" do
0
+ assert_match(/^test: #{prefix}a macro should have the tests named correctly/, self.to_s)
0
+ should_see_class_methods
0
+ should_see_a_context_block_like_a_Test_Unit_class
0
+ should_be_able_to_make_context_macros("Context ")
0
+ should "not define @blah" do
0
+ assert ! self.instance_variables.include?("@blah")
0
+ should "be able to define a should statement" do
0
+ should "see the name of my class as ShouldTest" do
0
+ assert_equal "ShouldTest", self.class.name
0
+ context "with a subcontext" do
0
+ should_be_able_to_make_context_macros("Context with a subcontext ")
0
+ context "Context with setup block" do
0
+ should "have @blah == 'blah'" do
0
+ assert_equal "blah", @blah
0
+ should "have name set right" do
0
+ assert_match(/^test: Context with setup block/, self.to_s)
0
+ context "and a subcontext" do
0
+ @blah = "#{@blah} twice"
0
+ should "be named correctly" do
0
+ assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s)
0
+ should "run the setup methods in order" do
0
+ assert_equal @blah, "blah twice"
0
+ context "Another context with setup block" do
0
+ should "have @blah == 'foo'" do
0
+ assert_equal "foo", @blah
0
+ should "have name set right" do
0
+ assert_match(/^test: Another context with setup block/, self.to_s)
0
+ should_eventually "pass, since it's a should_eventually" do
0
+ # Context creation and naming
0
+ def test_should_create_a_new_context
0
+ assert_nothing_raised do
0
+ Thoughtbot::Shoulda::Context.new("context name", self) do; end
0
+ def test_should_create_a_nested_context
0
+ assert_nothing_raised do
0
+ parent = Thoughtbot::Shoulda::Context.new("Parent", self) do; end
0
+ child = Thoughtbot::Shoulda::Context.new("Child", parent) do; end
0
+ def test_should_name_a_contexts_correctly
0
+ parent = Thoughtbot::Shoulda::Context.new("Parent", self) do; end
0
+ child = Thoughtbot::Shoulda::Context.new("Child", parent) do; end
0
+ grandchild = Thoughtbot::Shoulda::Context.new("GrandChild", child) do; end
0
+ assert_equal "Parent", parent.full_name
0
+ assert_equal "Parent Child", child.full_name
0
+ assert_equal "Parent Child GrandChild", grandchild.full_name
0
+ def test_should_have_should_hashes_when_given_should_statements
0
+ context = Thoughtbot::Shoulda::Context.new("name", self) do
0
+ should "be good" do; end
0
+ should "another" do; end
0
+ names = context.shoulds.map {|s| s[:name]}
0
+ assert_equal ["another", "be good"], names.sort
0
+ def test_should_capture_setup_and_teardown_blocks
0
+ context = Thoughtbot::Shoulda::Context.new("name", self) do
0
+ setup do; "setup"; end
0
+ teardown do; "teardown"; end
0
+ assert_equal "setup", context.setup_blocks.first.call
0
+ assert_equal "teardown", context.teardown_blocks.first.call
0
+ def test_should_create_shoulda_test_for_each_should_on_build
0
+ context = Thoughtbot::Shoulda::Context.new("name", self) do
0
+ context.expects(:create_test_from_should_hash).with(has_entry(:name => "one"))
0
+ context.expects(:create_test_from_should_hash).with(has_entry(:name => "two"))
0
+ def test_should_create_test_methods_on_build
0
+ tu_class = Test::Unit::TestCase
0
+ context = Thoughtbot::Shoulda::Context.new("A Context", tu_class) do
0
+ should "define the test" do; end
0
+ tu_class.expects(:define_method).with(:"test: A Context should define the test. ")
0
+ def test_should_create_test_methods_on_build_when_subcontext
0
+ tu_class = Test::Unit::TestCase
0
+ context = Thoughtbot::Shoulda::Context.new("A Context", tu_class) do
0
+ context "with a child" do
0
+ should "define the test" do; end
0
+ tu_class.expects(:define_method).with(:"test: A Context with a child should define the test. ")
0
+ # Test::Unit integration
0
+ def test_should_create_a_new_context_and_build_it_on_Test_Unit_context
0
+ Thoughtbot::Shoulda::Context.expects(:new).with("foo", kind_of(Class)).returns(c)
0
+ self.class.context "foo" do; end
0
+ def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should
0
+ Thoughtbot::Shoulda::Context.any_instance.expects(:should).with("rock", {}).returns(s)
0
+ Thoughtbot::Shoulda::Context.any_instance.expects(:build)
0
+ self.class.should "rock" do; end
0
+ def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should_eventually
0
+ Thoughtbot::Shoulda::Context.any_instance.expects(:should_eventually).with("rock").returns(s)
0
+ Thoughtbot::Shoulda::Context.any_instance.expects(:build)
0
+ self.class.should_eventually "rock" do; end
0
should "run a :before proc", :before => lambda { @value = "before" } do
0
assert_equal "before", @value
Comments
No one has commented yet.