Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. require File.dirname(__FILE__) + '/context-test-unit.rb'
  2. require 'rubygems'
  3. require 'rr'
  4.  
  5. class ContextTest < Test::Unit::TestCase
  6. attr_reader :callable
  7.  
  8. include RR::Adapters::TestUnit
  9.  
  10. def setup
  11. @callable = Object.new
  12. stub(callable).call!
  13. stub(callable).called? { false }
  14. end
  15.  
  16. test "has test helper" do
  17. assert true
  18. end
  19.  
  20. test "doesn't have before" do
  21. assert !callable.called?
  22. end
  23.  
  24. context "within a context block" do
  25. before do
  26. stub(callable).called? { true }
  27. end
  28.  
  29. test "has before" do
  30. assert callable.called?
  31. end
  32.  
  33. test "has after" do
  34. mock(callable).call!
  35. end
  36.  
  37. after do
  38. callable.call!
  39. end
  40. end
  41.  
  42. test "isn't called outside of context" do
  43. assert !callable.called?
  44. end
  45.  
  46. context "with nested contexts" do
  47. before do
  48. @call_count = 1
  49. end
  50.  
  51. test "should perform original before" do
  52. assert_equal 1, @call_count
  53. end
  54.  
  55. test "should before original after" do
  56. mock(callable).call!
  57. end
  58.  
  59. context "within nested context" do
  60. before do
  61. @call_count += 2
  62. end
  63.  
  64. test "should perform both original before and nested" do
  65. assert_equal 3, @call_count
  66. end
  67.  
  68. test "should perform both original after and nested" do
  69. mock(callable).call!.twice
  70. end
  71.  
  72. after do
  73. callable.call!
  74. end
  75. end
  76.  
  77. after do
  78. callable.call!
  79. end
  80. end
  81. end
Add Comment
Please, Sign In to add comment