Skip to content

Commit

Permalink
Write a failing test and make it pass
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Jul 23, 2019
1 parent 1263b00 commit 35a1c24
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/duck-model/duck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@

end

describe Duck do
describe "when re-arranging ranks " do
context "cannot be re-arranged" do

it "fails to save" do
patched_duck = Duck.new(
:name => 'Quacky',
:pond => 'Shin',
:age_position => 1,
)
age_ranker = Duck.rankers.detect {|ranker| ranker.name == :age }
Duck.expects(:rankers).once.returns([age_ranker])
patched_duck_ranker = age_ranker.with(patched_duck)
age_ranker.expects(:with).once.returns(patched_duck_ranker)
class << patched_duck_ranker
def current_first
nil
end

def current_at_rank(_rank)
true # something truthy
end
end
expect(patched_duck.save).to eq(false)
expect(patched_duck.errors.messages).to eq({
:age=>["Could not re-rank: current_first not found."]
})
end
end

end
end
describe Duck do

before {
Expand Down

0 comments on commit 35a1c24

Please sign in to comment.