例如,这两个测试:
it "fails to create given a bad player list" do
Team.new("Random name", bad_players).should raise_error
end
和
it "fails to create given a bad player list" do
expect {Team.new("Random name", bad_players)}.to raise_error
end
它们返回不同的输出(第一个失败,而第二个通过)。我希望两者都通过或失败取决于团队模型的内容。
完整的 RSpec 代码是:
require_relative 'team'
describe "Team" do
it "has a name" do
Team.new("Random name").should respond_to(:name)
end
it "has a list of players" do
Team.new("Random name").players.should be_kind_of Array
end
it "is favored if it has a celebrity on it"
it "complains if there is a bad word in the name"
context "given a bad list of players" do
let(:bad_players) { {} }
it "fails to create given a bad player list" do
expect { Team.new("Random name", bad_players) }.to raise_error
end
end
end
我认为'应该'会起作用的原因是因为'它“有一个名字”'测试中的类似语法。如果事实证明“应该”是不正确的,而“期望...到”是正确的,我很想知道何时使用一个与另一个。谢谢。