私はRSpecを学んでおり、チュートリアル以外のコードでは悲惨なことに失敗しているようです。だからこそ私はこの問題で頭を壁に叩いている。うまくいけば皆が助けることができる。RSpecのモジュール内でクラスをテストできません
のlib/NegotiGate
module NegotiGate
class Negotiation
def initialize(price1, price2)
@price1 = price1
@price2 = price2
end
def both_prices_equal?(price1, price2)
if @price1 == @price2
true
else
false
end
end
end
end
スペック/ NegotiGate_spec.rb
describe NegotiGate do
before(:each) do
@negotiate = Negotiation.new(10,10)
end
describe "Negotiation" do
describe ".both_prices_equal?" do
context "given the sellers price is the same as the buyers highest buying price" do
it 'returns true' do
expect(@negotiate.both_prices_equal?).to be_true
end
end
end
end
end
出力:
NegotiGate
Negotiation
.both_prices_equal?
given the sellers price is the same as the buyers highest buying price
returns true (FAILED - 1)
Failures:
1) NegotiGate Negotiation .both_prices_equal? given the sellers price is the same as the buyers highest buying price returns true
Failure/Error: @negotiate = Negotiation.new(10,10)
NameError:
uninitialized constant Negotiation
# ./spec/NegotiGate_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.00134 seconds (files took 0.15852 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/NegotiGate_spec.rb:11 # NegotiGate Negotiation .both_prices_equal? given the sellers price is the same as the buyers highest buying price returns true
すべてのヘルプは大幅にTDDの学生から理解されます。 乾杯!
ありがとうございます!私はちょうど始まっています、そして、時々周りを頭で包み込むためのテストは難しいです。 –