Initial import

This commit is contained in:
2008-03-02 16:04:34 -03:00
commit 5e4951fa47
798 changed files with 59730 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
class ContextTest < Test::Unit::TestCase # :nodoc:
context "context with setup block" do
setup do
@blah = "blah"
end
should "have @blah == 'blah'" do
assert_equal "blah", @blah
end
should "have name set right" do
assert_match(/^test: context with setup block/, self.to_s)
end
context "and a subcontext" do
setup do
@blah = "#{@blah} twice"
end
should "be named correctly" do
assert_match(/^test: context with setup block and a subcontext should be named correctly/, self.to_s)
end
should "run the setup methods in order" do
assert_equal @blah, "blah twice"
end
end
end
context "another context with setup block" do
setup do
@blah = "foo"
end
should "have @blah == 'foo'" do
assert_equal "foo", @blah
end
should "have name set right" do
assert_match(/^test: another context with setup block/, self.to_s)
end
end
context "context with method definition" do
setup do
def hello; "hi"; end
end
should "be able to read that method" do
assert_equal "hi", hello
end
should "have name set right" do
assert_match(/^test: context with method definition/, self.to_s)
end
end
context "another context" do
should "not define @blah" do
assert_nil @blah
end
end
should_eventually "should pass, since it's unimplemented" do
flunk "what?"
end
end

View File

@@ -0,0 +1,40 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
class Val
@@val = 0
def self.val; @@val; end
def self.inc(i=1); @@val += i; end
end
class HelpersTest < Test::Unit::TestCase # :nodoc:
context "an array of values" do
setup do
@a = ['abc', 'def', 3]
end
[/b/, 'abc', 3].each do |x|
should "contain #{x.inspect}" do
assert_raises(Test::Unit::AssertionFailedError) do
assert_does_not_contain @a, x
end
assert_contains @a, x
end
end
should "not contain 'wtf'" do
assert_raises(Test::Unit::AssertionFailedError) {assert_contains @a, 'wtf'}
assert_does_not_contain @a, 'wtf'
end
should "be the same as another array, ordered differently" do
assert_same_elements(@a, [3, "def", "abc"])
assert_raises(Test::Unit::AssertionFailedError) do
assert_same_elements(@a, [3, 3, "def", "abc"])
end
assert_raises(Test::Unit::AssertionFailedError) do
assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"])
end
end
end
end

View File

@@ -0,0 +1,26 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
class PrivateHelpersTest < Test::Unit::TestCase # :nodoc:
include ThoughtBot::Shoulda::ActiveRecord
context "get_options!" do
should "remove opts from args" do
args = [:a, :b, {}]
get_options!(args)
assert_equal [:a, :b], args
end
should "return wanted opts in order" do
args = [{:one => 1, :two => 2}]
one, two = get_options!(args, :one, :two)
assert_equal 1, one
assert_equal 2, two
end
should "raise ArgumentError if given unwanted option" do
args = [{:one => 1, :two => 2}]
assert_raises ArgumentError do
get_options!(args, :one)
end
end
end
end