Skip to content

Commit

Permalink
using named subjects in error spec
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldevries committed Oct 8, 2014
1 parent 2a9d4d7 commit b12df40
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions spec/lib/yamldiff_error_spec.rb
@@ -1,36 +1,36 @@
require "spec_helper"

describe YamldiffKeyError, "#to_s" do
subject { YamldiffKeyError.new('key', ['root', 'namespace']) }
subject(:key_error) { YamldiffKeyError.new('key', ['root', 'namespace']) }

it "outputs human readable text" do
expect(subject.to_s).to eql "Missing key: root.namespace.key"
expect(key_error.to_s).to eql "Missing key: root.namespace.key"
end
end

describe YamldiffKeyValueTypeError, "#to_s" do
subject { YamldiffKeyValueTypeError.new('key', ['root', 'namespace']) }
subject(:key_value_type_error) { YamldiffKeyValueTypeError.new('key', ['root', 'namespace']) }

it "outputs human readable text" do
expect(subject.to_s).to eql "Key value type mismatch: root.namespace.key"
expect(key_value_type_error.to_s).to eql "Key value type mismatch: root.namespace.key"
end
end

describe YamldiffKeyValueError, "#to_s" do
context "without a diff" do
subject { YamldiffKeyValueError.new('key', ['root', 'namespace']) }
subject(:key_value_error) { YamldiffKeyValueError.new('key', ['root', 'namespace']) }

it "outputs human readable text" do
expect(subject.to_s).to eql "Key content differs: root.namespace.key"
expect(key_value_error.to_s).to eql "Key content differs: root.namespace.key"
end
end

context "with a diff" do
let(:diff) { Diffy::Diff.new("foo\n", "bar\n") }
subject { YamldiffKeyValueError.new('key', ['root', 'namespace'], diff) }
subject(:key_value_error) { YamldiffKeyValueError.new('key', ['root', 'namespace'], diff) }

it "outputs diff if given" do
expect(subject.to_s).to eql <<-OUTPUT
expect(key_value_error.to_s).to eql <<-OUTPUT
Key content differs: root.namespace.key
Diff:
-foo
Expand Down

0 comments on commit b12df40

Please sign in to comment.