2012-01-10 6 views
1

私は単純なtest\specを実行しようとしていますが、エラーが発生しています。エラーは、テストが失敗した場合にのみ発生します。未定義のメソッドascii_compatible?エンコード用:US-ASCII

begin 
    require 'rubygems' 
    require 'test/spec' 
rescue LoadError 
    puts "==> you need test/spec to run tests. {sudo gem install test-spec}" 
end 


context "Foo" do 
    specify "should bar" do 
    "ttes".should.equal "tes" 
    end 
end 

1) Error: test_spec {Foo} 001 should bar: NoMethodError: undefined method ascii_compatible?' for #<Encoding:US-ASCII> person.rb:11:in block (2 levels) in '

+0

'person.rb'はどのように見えますか?具体的には8〜14行程度。 – Batkins

+0

私の投稿にあるエラーメッセージの上のコードは 'person.rb'です – Omnipresent

答えて

1

私は推測することができますが、ここで起こって非常に奇妙な何かがあります。あなたはRubyのバージョンなどを混ぜていますか? Rubyのバージョンと互換性のない宝石を使用していますか?すべてのエンコードインスタンスはRuby 1.9ではascii_compatible?に応答する必要があります。したがって、おそらく1.8を使用しています(Windowsのように見えますが、これはおそらくそうです)。

また、フルスタックトレースを使用すると、begin/rescueで例外をキャッチし、それにbacktraceを呼び出すことができます(大きな助けになるでしょう。あなたはtest-specモジュールの正確なラインが失敗したかを調べるでしょうその方法。

また、テストスペックは非常に積極的に開発宝石ではないようです。たぶん、オプションは同じ目的を持って、代わりに、より広く使用されるツールをRSpecを使用することです。

0

私はルビーを実行している同様の問題を得ていました1.9.1。Windows上で私の環境は、以前はRubyを実行するように設定されていました私は組み込み開発のための自動テストのスクリプトを作成しました。

1.9.3をインストールしようとしましたが、問題はまだ残りました。最終的に1.9.1と1.9.3の両方をアンインストールし、Ruby 1.9.3とテストユニットの宝石(2.4.5)を再インストールしました。

0

Ruby 1.9.1の私のバージョンには、「テストユニット」に依存する宝石がありました。少なくとも1台の がtest-unit-2.4.7のインストールを強制しました。私にとっては、 'test-unit-2.4.7' gemを削除することで問題は解決しました。

は、テストユニット-2.4.7では、私たちは、このコードがあります: '?ascii_compatible'

in /home/davei/.gem/ruby/1.9.1/gems/test-unit-2.4.7/lib/test/unit/assertions.rb 
    1483 
    1484   def ensure_diffable_string(string) 
    1485    if string.respond_to?(:encoding) and 
=> 1486     !string.encoding.ascii_compatible? 
    1487    string = string.dup.force_encoding("ASCII-8BIT") 
    1488    end 
    1489    string 
    1490   end 

はおそらくエンコードのすべてのインスタンスがサポートする必要がありますがただし、Ruby 1.9.1p378ではそうではありません。

(rdb:1) p string.encoding 
#<Encoding:US-ASCII> 
(rdb:1) p string.encoding.public_methods 
[:to_s, :inspect, :name, :names, :dummy?, :_dump, :dbg, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :nil?, :===, :=~, :!~, :eql?, :class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :define_singleton_method, :hash, :__id__, :object_id, :to_enum, :enum_for, :gem, :pretty_inspect, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__] 

「ascii_compatible?」が見つかりました。エンコーディングのための欠落:UTF-8も同様です。

関連する問題