Context Problem?

3 views
Skip to first unread message

Chris Gardner

unread,
Sep 23, 2009, 3:53:39 PM9/23/09
to shoulda
Ruby: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
Shoulda: thoughtbot-shoulda (2.10.2)

I thought the outermost context would be run only once. It seems to
be running multiple times. I took one of the examples on the shoulda
site and added some puts statements.

require 'test/unit'
require 'shoulda'

class QueueTest < Test::Unit::TestCase
context "A Queue instance" do
setup do
puts "OUTER SETUP"
@queue = Queue.new
end

should "respond to :push" do
assert_respond_to @queue, :push
end

context "with a single element" do
setup { puts "INNER SETUP"; @queue.push(:something) }

should "return that element on :pop" do
assert_equal :something, @queue.pop
end

should "return 1 on :size" do
assert_equal 1, @queue.size
end
end
end
end

I expected to see OUTER SETUP printed only once. But here is what was
printed:

Started
OUTER SETUP
.OUTER SETUP
INNER SETUP
.OUTER SETUP
INNER SETUP

Should this be happening? I thought the outermost context sets up
everything only once.

Ryan Angilly

unread,
Sep 23, 2009, 3:58:56 PM9/23/09
to sho...@googlegroups.com
Nope.  The entire setup chain runs every time.  Unless you play games (http://m.onkey.org/2009/9/20/make-your-shoulda-tests-faster-with-fast_context)
Reply all
Reply to author
Forward
0 new messages