加载错误:没有这样的文件加载 - 升级到watir 4.0.2后的watir / testcase

时间:2012-12-21 07:33:30

标签: ruby watir

我刚从watir 4.0.2升级到watir 2.0.4,我收到以下错误,

C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:60:in `gem_original
_require': no such file to load -- watir/testcase (LoadError)

我搜索了错误,但无法找到解决方案。

宝石列表

abstract (1.0.0)                    
actionmailer (3.2.8, 3.0.0)                 
actionpack (3.2.8, 3.0.0)                   
activemodel (3.2.8, 3.0.0)                  
activerecord (3.2.8, 3.0.0)                 
activeresource (3.2.8, 3.0.0)                   
activesupport (3.2.8, 3.0.0)                    
addressable (2.3.2)                 
akami (1.2.0)                   
arel (3.0.2, 1.0.1)                 
Ascii85 (1.0.1)                 
builder (3.0.0, 2.1.2)                  
bundler (1.0.22)                    
childprocess (0.3.6)                    
commandline (0.7.10)                    
commonwatir (4.0.0, 2.0.4)                  
erubis (2.7.0, 2.6.6)                   
ffi (1.1.5)                 
gyoku (0.4.6)                   
hike (1.2.1)                    
hoe (3.0.8)                 
httpi (0.9.7)                   
i18n (0.6.1, 0.4.2)                 
journey (1.0.4)                 
libwebsocket (0.1.5)                    
mail (2.4.4, 2.2.19)                    
mime-types (1.19, 1.18)                 
mini_magick (3.2.1)                 
multi_json (1.3.6)                  
mysql2 (0.3.11 x86-mingw32, 0.2.18 x86-mingw32, 0.2.6 x86-mingw32)                  
nokogiri (1.5.5 x86-mingw32)                    
nori (1.1.3)                    
pdf-reader (1.1.1)                  
polyglot (0.3.3)                    
rack (1.4.1, 1.2.5)                 
rack-cache (1.2)                    
rack-mount (0.6.14)                 
rack-ssl (1.3.2)                    
rack-test (0.6.2, 0.5.7)                    
rails (3.0.0)                   
railties (3.0.0)                    
rake (0.8.7)                    
rautomation (0.7.3, 0.6.3)                  
ruby-rc4 (0.1.5)                    
rubygems-update (1.8.24)                    
rubyzip (0.9.9)                 
s4t-utils (1.0.4)                   
savon (0.9.9)                   
selenium-webdriver (2.26.0)                 
sprockets (2.1.3)                   
sqlite3 (1.3.6 x86-mingw32)                 
sqlite3-ruby (1.3.3)                    
subexec (0.0.4)                 
text-format (1.0.0)                 
text-hyphen (1.0.2)                 
thor (0.14.6)                   
tilt (1.3.3)                    
treetop (1.4.10)                    
tzinfo (0.3.33)                 
user-choices (1.1.6.1)                  
wasabi (2.1.0)                  
watir (4.0.2 x86-mingw32, 2.0.4)                    
watir-classic (3.3.0)                   
watir-webdriver (0.6.2)                 
websocket (1.0.6)                   
win32-api (1.4.8 x86-mingw32)                   
win32-process (0.6.6)                   
win32screenshot (1.0.7)                 
windows-api (0.4.2)                 
windows-pr (1.2.2)                  
xml-simple (1.1.1)                  


Ruby Version:ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]

对此有什么想法吗?

2 个答案:

答案 0 :(得分:1)

watir/testcase最近从Watir中删除了。我找不到它的删除时间,但信息位于CHANGES文件或Git history

答案 1 :(得分:1)

虽然离开Watir :: TestCase可能会更好,但如果你确实需要或想要使用它,你可以通过从3.0复制文件来重新创建它。

假设您使用的是Ruby 1.8,默认情况下仍然安装了测试单元gem,您可以执行以下操作:

1)使用以下代码创建名为“watir_testcase.rb”的文件,该文件基本上是3.0版本的testcase.rb和assertions.rb文件的副本:

require 'watir-classic'
require 'test/unit'
require 'test/unit/assertions'

module Watir
  # Verification methods used by Watir::TestCase
  module Assertions
  include Test::Unit::Assertions

    # Log a failure if the boolean is true. The message is the failure message logged.
    # Whether true or false, the assertion count is incremented.
    def verify boolean, message = 'verify failed.'
      add_assertion
      add_failure message.to_s, caller unless boolean
    end

    def verify_equal expected, actual, message=nil
      full_message = build_message(message, <<EOT, expected, actual)
<?> expected but was
<?>.
EOT
      verify(expected == actual, full_message)
    end
    def verify_match pattern, string, message=nil
      pattern = case(pattern)
      when String
        Regexp.new(Regexp.escape(pattern))
      else
        pattern
      end
      full_message = build_message(message, "<?> expected to be =~\n<?>.", string, pattern)
      verify(string =~ pattern, full_message)
    end

  end

end

module Test::Unit::Assertions
    def assert_false(boolean, message=nil)
        _wrap_assertion do
            assert_block("assert should not be called with a block.") { !block_given? }
            assert_block(build_message(message, "<?> is not false.", boolean)) { !boolean }
        end
    end
end 

module Watir

  # This is a 'test/unit' testcase customized to exeucte test methods sequentially by default
  # and extra assertions
  #
  class TestCase < Test::Unit::TestCase
    include Watir::Assertions
    @@order = :sequentially
    def initialize name
      throw :invalid_test if name == :default_test && self.class == Watir::TestCase
      super
    end        
    class << self
      attr_accessor :test_methods, :order
      def test_methods
        @test_methods ||= []
      end
      def order
        @order || @@order
      end
      def default_order= order
        @@order = order
      end
      def sorted_test_methods
        case order
        when :alphabetically then          test_methods.sort
        when :sequentially then            test_methods
        when :reversed_sequentially then   test_methods.reverse
        when :reversed_alphabetically then test_methods.sort.reverse
        else raise ArgumentError, "Execute option not supported: #{@order}"
        end
      end
      def suite
        suite = Test::Unit::TestSuite.new(name)
        sorted_test_methods.each do |test|
          catch :invalid_test do
            suite << new(test)
          end
        end
        if (suite.empty?)
          catch :invalid_test do
            suite << new(:default_test)
          end
        end
        return suite
      end
      def method_added id
        name = id.id2name
        test_methods << name if name =~ /^test./
      end
      def execute order
        @order = order
      end
    end
    public :add_assertion
  end    

end  

2)在测试用例文件中,更改:

require 'watir/testcase'

要求新创建的文件:

require './watir_testcase'

(确保路径对于保存文件的位置是正确的)