File: command_state_spec.rb

package info (click to toggle)
pry 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,772 kB
  • sloc: ruby: 21,692; sh: 17; makefile: 11
file content (51 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

RSpec.describe Pry::CommandState do
  describe ".default" do
    it "returns the default command state" do
      expect(described_class.default).to be_a(described_class)
    end

    context "when called multiple times" do
      it "returns the same command state" do
        first_state = described_class.default
        second_state = described_class.default
        expect(first_state).to eql(second_state)
      end
    end
  end

  describe "#state_for" do
    it "returns a state for the matching command" do
      subject.state_for(Pry::Command::Cd).old_stack = 1
      expect(subject.state_for(Pry::Command::Cd).old_stack).to eq(1)
    end

    it "returns new state for new command" do
      expect(subject.state_for(Pry::Command::Cd))
        .not_to equal(subject.state_for(Pry::Command::Play))
    end

    it "memoizes state for the same command" do
      state_a = subject.state_for(Pry::Command::Cd)
      state_b = subject.state_for(Pry::Command::Cd)
      expect(state_a).to equal(state_b)
    end
  end

  describe "#reset" do
    it "resets the command state for the given command" do
      subject.state_for(Pry::Command::Cd).old_stack = 1
      subject.reset(Pry::Command::Cd)
      expect(subject.state_for(Pry::Command::Cd).old_stack).to be_nil
    end

    it "doesn't reset command state for other commands" do
      subject.state_for(Pry::Command::Cd).old_stack = 1
      subject.state_for(Pry::Command::WatchExpression).watch_expressions = 1
      subject.reset(Pry::Command::Cd)

      expect(subject.state_for(Pry::Command::WatchExpression).watch_expressions).to eq(1)
    end
  end
end