Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby:奇怪的字符串比较断言行为_Ruby_String_Unit Testing - Fatal编程技术网

Ruby:奇怪的字符串比较断言行为

Ruby:奇怪的字符串比较断言行为,ruby,string,unit-testing,Ruby,String,Unit Testing,有人能解释一下这里发生了什么吗?我有一个带有一些静态方法的简单类,我想测试它们 yaqueline/build/converters/asciidoconverter.rb # encoding: UTF-8 require 'asciidoctor' module Yaqueline module Build module Converters class AsciiDocConverter < Converter class <<

有人能解释一下这里发生了什么吗?我有一个带有一些静态方法的简单类,我想测试它们

yaqueline/build/converters/asciidoconverter.rb

# encoding: UTF-8
require 'asciidoctor'

module Yaqueline
  module Build
    module Converters

      class AsciiDocConverter < Converter

        class << self

          def matches path
            path =~ /\.(asciidoc|adoc|ascii|ad)$/
          end

          def convert content
             html = Asciidoctor.convert content, to_file: false, safe: :safe
              html = get_guts_out_of_body html
              puts "asciidoc #{html}"
              html
            end

            def get_guts_out_of_body html
              if html =~ /<body>/
                puts "get guts: #{html}"
                return html.match(%r{(?<=<body>).*(?=</body>)})
              end
              html
            end

          end # class << self

        end # class

      end
    end
  end
当使用

$ rake test TEST=test/build/converters/asciidocconverter_test.rb
结果在我看来很好:

Started
get guts: 
     <html>
       <head>
     <title>Hej värld</title>
       </head>
       <body>SUCCESS</body>
     </html>
guts was 'SUCCESS'
F
===============================================================================================================================================================================
Failure:
  guts was 'SUCCESS', expected 'SUCCESS'.
  <false> is not true.
test: AsciidocConverter should be able to get body html from a document. (TestAsciidocConverter)
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:37:in `block in <class:TestAsciidocConverter>'
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:39:in `instance_exec'
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:39:in `block in create_test_from_should_hash'
===============================================================================================================================================================================
也许这有助于了解我正在使用的帽子测试工具

有人能看到错误或解释发生了什么吗


欢呼声

检查正在比较的值的类型。其中一个不是字符串。(因此,它不能等于字符串)

guts=html.match(%r{(?)#
“成功”

检查要比较的值的类型。其中一个不是字符串。(因此,它不能等于字符串)

guts=html.match(%r{(?)#
“成功”

缩进故障来自粘贴到SO编辑器。它们是精细IRL。缩进故障来自粘贴到SO编辑器。它们是精细IRL。
Started
get guts: 
     <html>
       <head>
     <title>Hej värld</title>
       </head>
       <body>SUCCESS</body>
     </html>
guts was 'SUCCESS'
F
===============================================================================================================================================================================
Failure:
  guts was 'SUCCESS', expected 'SUCCESS'.
  <false> is not true.
test: AsciidocConverter should be able to get body html from a document. (TestAsciidocConverter)
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:37:in `block in <class:TestAsciidocConverter>'
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:39:in `instance_exec'
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:39:in `block in create_test_from_should_hash'
===============================================================================================================================================================================
# Add dependencies required to use your gem here.
# Example:
#   gem "activesupport", ">= 2.3.5"

gem 'mercenary'
gem 'safe_yaml'
gem 'kramdown'
gem 'colorator'
gem 'pathutil'
gem 'nokogiri'
gem 'sass'
gem 'listen', '~> 3.0'
gem 'asciidoctor'
gem 'tilt'
gem 'erubis'

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
  gem "rdoc", "~> 3.12"
  gem "bundler", "~> 1.0"
  gem "juwelier", "~> 2.1.0"
  gem "simplecov", ">= 0"
  gem 'rubocop', '~> 0.48.1', require: false
  gem 'thin' # or whatever I end up with
  gem 'minitest'
  gem 'test-unit'
  gem 'shoulda'
end
 guts = html.match(%r{(?<=<body>).*(?=</body>)})
 guts # => #<MatchData "SUCCESS">
 guts.to_s # => "SUCCESS"