差异
在适当的情况下,错误消息将自动包含差异。
多行字符串的差异
给定一个名为“example_spec.rb”的文件,其中包含
RSpec.describe "a multiline string" do
it "is like another string" do
expected = <<-EXPECTED
this is the
expected
string
EXPECTED
actual = <<-ACTUAL
this is the
actual
string
ACTUAL
expect(actual).to eq(expected)
end
end
当我运行 rspec example_spec.rb
然后输出应包含
Diff:
@@ -1,4 +1,4 @@
this is the
- expected
+ actual
string
多行字符串和 diff-lcs 1.4 上正则表达式的差异
给定一个名为“example_spec.rb”的文件,其中包含
RSpec.describe "a multiline string" do
it "is like another string" do
expected = /expected/m
actual = <<-ACTUAL
this is the
actual
string
ACTUAL
expect(actual).to match expected
end
end
当我运行 rspec example_spec.rb
然后输出应包含
Diff:
@@ -1,3 +1,5 @@
-/expected/m
+this is the
+ actual
+ string
多行字符串和 diff-lcs 1.3 上正则表达式的差异
给定一个名为“example_spec.rb”的文件,其中包含
RSpec.describe "a multiline string" do
it "is like another string" do
expected = /expected/m
actual = <<-ACTUAL
this is the
actual
string
ACTUAL
expect(actual).to match expected
end
end
当我运行 rspec example_spec.rb
然后输出应包含
Diff:
@@ -1,2 +1,4 @@
-/expected/m
+this is the
+ actual
+ string
单行字符串没有差异
给定一个名为“example_spec.rb”的文件,其中包含
RSpec.describe "a single line string" do
it "is like another string" do
expected = "this string"
actual = "that string"
expect(actual).to eq(expected)
end
end
当我运行 rspec example_spec.rb
然后输出不应包含“Diff:”。
数字没有差异
给定一个名为“example_spec.rb”的文件,其中包含
RSpec.describe "a number" do
it "is like another number" do
expect(1).to eq(2)
end
end
当我运行 rspec example_spec.rb
然后输出不应包含“Diff:”。