Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

A simple test to ensure setup and teardown blocks are run in the corr…

…ect order.
  • Loading branch information...
commit fa817cce4c94bceb768cda1a350177998db80089 1 parent 65db0a3
Phil Crosby philc authored

Showing 1 changed file with 82 additions and 0 deletions. Show diff stats Hide diff stats

  1. +82 0 test/scope_test.rb
82 test/scope_test.rb
... ... @@ -0,0 +1,82 @@
  1 +require "rubygems"
  2 +require File.expand_path(File.dirname(__FILE__) + "/../lib/scope.rb")
  3 +
  4 +class ScopeTest < Scope::TestCase
  5 + @@has_run = []
  6 +
  7 + def has_run(name) @@has_run.push(name) end
  8 + def self.tests_executed() @@has_run end
  9 +
  10 + setup_once do
  11 + has_run "setup_once"
  12 + end
  13 +
  14 + setup do
  15 + has_run "setup"
  16 + end
  17 +
  18 + should "A" do
  19 + has_run "A"
  20 + end
  21 +
  22 + context "context" do
  23 + setup_once do
  24 + has_run "context:setup_once"
  25 + end
  26 +
  27 + setup do
  28 + has_run "context:setup"
  29 + end
  30 +
  31 + should "Z" do
  32 + has_run "context:Z"
  33 + end
  34 +
  35 + should "A" do
  36 + has_run "context:A"
  37 + end
  38 +
  39 + teardown do
  40 + has_run "context:teardown"
  41 + end
  42 +
  43 + teardown_once do
  44 + has_run "context:teardown_once"
  45 + end
  46 + end
  47 +
  48 + teardown do
  49 + has_run "teardown"
  50 + end
  51 +
  52 + teardown_once do
  53 + has_run "teardown_once"
  54 + end
  55 +end
  56 +
  57 +#
  58 +# I know, I know -- it's not using scope to run itself. Meta-fail.
  59 +#
  60 +
  61 +ScopeTest.test_methods.each do |test_name|
  62 + # This simulates MiniTest's run() method.
  63 + instance = ScopeTest.new(test_name)
  64 + instance.run(nil)
  65 +end
  66 +
  67 +expected = %W(
  68 + setup_once
  69 + setup A teardown
  70 + context:setup_once
  71 + setup context:setup context:Z context:teardown teardown
  72 + setup context:setup context:A context:teardown teardown
  73 + context:teardown_once
  74 + teardown_once
  75 +)
  76 +
  77 +if expected != ScopeTest.tests_executed
  78 + puts "Expected\n#{expected.inspect}\n but was\n#{ScopeTest.tests_executed.inspect}"
  79 + exit 1
  80 +else
  81 + puts "Success."
  82 +end

0 comments on commit fa817cc

Please sign in to comment.
Something went wrong with that request. Please try again.