Files
ubicloud/spec/prog/learn_memory_spec.rb
Enes Cakir 60b69117dd Clean up nap/hop/exit expectations in specs
We have custom `RSpec::Matchers` for flow control exceptions. There's no
need to manually expect to receive these functions. Additionally, we use
these matchers in our codebase as a single line in general. There's no
need to extend them to 3 lines unless it's too long.

This cleanup has revealed some issues that need fixing:

- learn_network_spec.rb: Our default stack value is `[{}]`. `[]` is not
  expected, and fails our code when popped.

- rekey_nic_tunnel.rb: `pop` raises an exception, so the code can't run
  after it. `return` is unnecessary.

- base.rb: Our default stack value is `[{}]`, so `frame&` is
  unnecessary. We don't need to write extra test to cover this branch.
  It was covered previously because of the wrong stack value at
  `learn_network_spec.rb`.
2023-10-31 18:04:34 +03:00

37 lines
840 B
Ruby

# frozen_string_literal: true
require_relative "../model/spec_helper"
RSpec.describe Prog::LearnMemory do
subject(:lm) { described_class.new(Strand.new) }
let(:four_units) do
<<EOS
Size: 16 GB
Size: 16 GB
Size: 16 GB
Size: 16 GB
EOS
end
describe "#start" do
it "exits, saving the number of memory" do
sshable = instance_double(Sshable)
expect(sshable).to receive(:cmd).with("sudo /usr/sbin/dmidecode -t memory | fgrep Size:").and_return(four_units)
expect(lm).to receive(:sshable).and_return(sshable)
expect { lm.start }.to exit({mem_gib: 64})
end
end
describe "#parse_sum" do
it "crashes if an unfamiliar unit is provided" do
expect {
lm.parse_sum(<<EOS)
Size: 16384 MB
EOS
}.to raise_error RuntimeError, "BUG: unexpected dmidecode unit"
end
end
end