-3
:残念ながら、次の試験はRubyの配列のオープンクラスにメソッドを追加する私は、コアのRuby <code>Array</code>クラスに<code>all_empty?</code>メソッドを追加しようとしています
class Array
def all_empty?
...
end
end
は失敗:
require "spec_helper"
describe Array do
context "#all_empty?" do
it "returns true if all elements of the Array are empty" do
expect(["", "", ""].all_empty?).to be_truthy
end
end
end
Iを次のNoMethodErrorを取得します。
NoMethodError:
undefined method `all_empty?' for ["", "", ""]:Array
Did you mean? empty?
# ./spec/core_extensions_spec.rb:6:in `block (3 levels) in <top (required)>'
仕様をr既にall_empty?
メソッドを定義していることを認識していますか?
EDIT:これは、以下のコメントにするために頼まれspec_helper.rbファイルの内容です:
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require_relative "../lib/tic_tac_toe.rb"
「spec_helper」とは何ですか?コードはどのように読み込まれますか? – sawa
'Array' Monkeypatchがロードされていることを確認してください._before_ testが実行されています。 – mudasobwa