Skip to content

Commit

Permalink
refactor(examples): structure contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Jan 13, 2024
1 parent 7d03868 commit f6c238f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@

example_group "class methods" do
describe ".result" do
context "when text is NOT passed" do
subject(:result) { described_class.result }
context "when `BuildCloud` is successful" do
context "when text is NOT passed" do
subject(:result) { described_class.result }

let(:cloud) do
<<~HEREDOC
______________
< Hello World! >
--------------
HEREDOC
end
let(:cloud) do
<<~HEREDOC
______________
< Hello World! >
--------------
HEREDOC
end

it "returns success with cloud with \"Hello World!\"" do
expect(result).to be_success.with_data(cloud: cloud)
it "returns success with cloud with \"Hello World!\"" do
expect(result).to be_success.with_data(cloud: cloud)
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@

example_group "class methods" do
describe ".result" do
subject(:result) { described_class.result }

let(:cow) do
<<~'HEREDOC'.split("\n").map { |line| " " * 10 + line }.join("\n")
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
HEREDOC
end

it "returns success with data" do
expect(result).to be_success.with_data(cow: cow)
context "when `BuildCow` is successful" do
subject(:result) { described_class.result }

let(:cow) do
<<~'HEREDOC'.split("\n").map { |line| " " * 10 + line }.join("\n")
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
HEREDOC
end

it "returns success with data" do
expect(result).to be_success.with_data(cow: cow)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,88 +9,79 @@
include ConvenientService::RSpec::Matchers::Results
include ConvenientService::RSpec::Matchers::IncludeModule

let(:text) { "foo" }
let(:out) { Tempfile.new }

example_group "modules" do
subject { described_class }

it { is_expected.to include_module(ConvenientService::Standard::Config) }
end

example_group "attributes" do
include ConvenientService::RSpec::PrimitiveMatchers::HaveAttrReader

subject { service }

let(:service) { described_class.new(text: text, out: out) }

it { is_expected.to have_attr_reader(:text) }
it { is_expected.to have_attr_reader(:out) }
end

example_group "class methods" do
describe ".result" do
context "when `text` is NOT passed" do
subject(:result) { described_class.result(out: out) }

let(:content) do
<<~'HEREDOC'
______________
< Hello World! >
--------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
HEREDOC
end
context "when `Print` is successful" do
let(:text) { "foo" }
let(:out) { Tempfile.new }

context "when `text` is NOT passed" do
subject(:result) { described_class.result(out: out) }

let(:content) do
<<~'HEREDOC'
______________
< Hello World! >
--------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
HEREDOC
end

it "returns success" do
expect(result).to be_success.without_data
end
it "returns success" do
expect(result).to be_success.without_data
end

it "prints cloud and cow to out" do
result
it "prints cloud and cow to out" do
result

expect(out.tap(&:rewind).read).to eq(content)
expect(out.tap(&:rewind).read).to eq(content)
end
end
end

context "when `text` is passed" do
subject(:result) { described_class.result(text: text, out: out) }

let(:content) do
<<~'HEREDOC'
_____
< Hi! >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
HEREDOC
end
context "when `text` is passed" do
subject(:result) { described_class.result(text: text, out: out) }

let(:content) do
<<~'HEREDOC'
_____
< Hi! >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
HEREDOC
end

let(:text) { "Hi!" }
let(:text) { "Hi!" }

it "returns `success`" do
expect(result).to be_success.without_data
end
it "returns `success`" do
expect(result).to be_success.without_data
end

it "prints cloud and cow to out" do
result
it "prints cloud and cow to out" do
result

expect(out.tap(&:rewind).read).to eq(content)
end
expect(out.tap(&:rewind).read).to eq(content)
end

context "when `out` is NOT passed" do
subject(:result) { described_class.result(text: text) }
context "when `out` is NOT passed" do
subject(:result) { described_class.result(text: text) }

it "defaults to `stdout`" do
expect { result }.to output(content).to_stdout
it "defaults to `stdout`" do
expect { result }.to output(content).to_stdout
end
end
end
end
Expand Down

0 comments on commit f6c238f

Please sign in to comment.