PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/gemcache/ruby/1.9.1/gems/state_machine-1.1.2/test/unit/integrations/base_test.rb

https://bitbucket.org/technopunk2099/metasploit-framework
Ruby | 103 lines | 81 code | 21 blank | 1 comment | 0 complexity | 81bd82b5c872e07815cc0392f3a5bedc MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, LGPL-2.1, GPL-2.0, MIT
  1. require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
  2. # Load library
  3. require 'rubygems'
  4. module BaseTest
  5. class IntegrationTest < Test::Unit::TestCase
  6. def test_should_have_an_integration_name
  7. assert_equal :base, StateMachine::Integrations::Base.integration_name
  8. end
  9. def test_should_not_be_available
  10. assert !StateMachine::Integrations::Base.available?
  11. end
  12. def test_should_not_have_any_matching_ancestors
  13. assert_equal [], StateMachine::Integrations::Base.matching_ancestors
  14. end
  15. def test_should_not_match_any_classes
  16. assert !StateMachine::Integrations::Base.matches?(Class.new)
  17. end
  18. def test_should_not_have_a_locale_path
  19. assert_nil StateMachine::Integrations::Base.locale_path
  20. end
  21. end
  22. class IncludedTest < Test::Unit::TestCase
  23. def setup
  24. @integration = Module.new
  25. StateMachine::Integrations.const_set('Custom', @integration)
  26. @integration.class_eval do
  27. include StateMachine::Integrations::Base
  28. end
  29. end
  30. def test_should_not_have_any_defaults
  31. assert_nil @integration.defaults
  32. end
  33. def test_should_not_have_any_versions
  34. assert_equal [], @integration.versions
  35. end
  36. def test_should_track_version
  37. version1 = @integration.version '1.0' do
  38. def self.active?
  39. true
  40. end
  41. end
  42. version2 = @integration.version '2.0' do
  43. def self.active?
  44. false
  45. end
  46. end
  47. assert_equal [version1, version2], @integration.versions
  48. end
  49. def test_should_allow_active_versions_to_override_default_behavior
  50. @integration.class_eval do
  51. def version1_included?
  52. false
  53. end
  54. def version2_included?
  55. false
  56. end
  57. end
  58. version1 = @integration.version '1.0' do
  59. def self.active?
  60. true
  61. end
  62. def version1_included?
  63. true
  64. end
  65. end
  66. version2 = @integration.version '2.0' do
  67. def self.active?
  68. false
  69. end
  70. def version2_included?
  71. true
  72. end
  73. end
  74. @machine = StateMachine::Machine.new(Class.new, :integration => :custom)
  75. assert @machine.version1_included?
  76. assert !@machine.version2_included?
  77. end
  78. def teardown
  79. StateMachine::Integrations.send(:remove_const, 'Custom')
  80. end
  81. end
  82. end