Skip to content

Commit

Permalink
Change tests to reduce multiple expectations to one per example
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 27, 2023
1 parent b9d6486 commit 3d5bbdb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
24 changes: 12 additions & 12 deletions spec/unit/alignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,45 @@
it "creates alignment from a string with a single value" do
alignment = described_class.from("right")

expect(alignment.horizontal).to eq("right")
expect(alignment.vertical).to eq("center")
expect(alignment).to have_attributes(horizontal: "right",
vertical: "center")
end

it "creates alignment from a string with a single value and default" do
alignment = described_class.from("right", default: "bottom")

expect(alignment.horizontal).to eq("right")
expect(alignment.vertical).to eq("bottom")
expect(alignment).to have_attributes(horizontal: "right",
vertical: "bottom")
end

it "creates alignment from a string with two values space-separated" do
alignment = described_class.from("right top")

expect(alignment.horizontal).to eq("right")
expect(alignment.vertical).to eq("top")
expect(alignment).to have_attributes(horizontal: "right",
vertical: "top")
end

it "creates alignment from a string with a comma separator" do
alignment = described_class.from("right,top")

expect(alignment.horizontal).to eq("right")
expect(alignment.vertical).to eq("top")
expect(alignment).to have_attributes(horizontal: "right",
vertical: "top")
end

it "creates alignment from a string with a comma and space separator" do
alignment = described_class.from("right , top")

expect(alignment.horizontal).to eq("right")
expect(alignment.vertical).to eq("top")
expect(alignment).to have_attributes(horizontal: "right",
vertical: "top")
end
end

describe ".[]" do
it "creates alignemt with array-like helper method" do
alignment = described_class["right", "top"]

expect(alignment.horizontal).to eq("right")
expect(alignment.vertical).to eq("top")
expect(alignment).to have_attributes(horizontal: "right",
vertical: "top")
end

it "raises when value is invalid" do
Expand Down
12 changes: 10 additions & 2 deletions spec/unit/run_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# frozen_string_literal: true

RSpec.describe Slideck, ".run" do
it "runs the runner" do
it "creates a CLI with a runner" do
cli = instance_spy(Slideck::CLI)
allow(Slideck::CLI).to receive(:new).and_return(cli)

described_class.run(%w[slides.md], {"NO_COLOR" => true})
described_class.run

expect(Slideck::CLI).to have_received(:new)
.with(instance_of(Slideck::Runner), $stdout, $stderr)
end

it "starts the CLI with a slides file and NO_COLOR=true variable" do
cli = instance_spy(Slideck::CLI)
allow(Slideck::CLI).to receive(:new).and_return(cli)

described_class.run(%w[slides.md], {"NO_COLOR" => true})

expect(cli).to have_received(:start)
.with(%w[slides.md], {"NO_COLOR" => true})
end
Expand Down
6 changes: 2 additions & 4 deletions spec/unit/tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
it "changes by moving forward and backward" do
tracker = described_class.new(0, 5)

tracker = tracker.next
tracker = tracker.next
expect(tracker.current).to eq(2)

2.times { tracker = tracker.next }
tracker = tracker.previous

expect(tracker.current).to eq(1)
end

Expand Down

0 comments on commit 3d5bbdb

Please sign in to comment.