File: client_spec.rb

package info (click to toggle)
ruby-neovim 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 548 kB
  • sloc: ruby: 4,178; sh: 23; makefile: 4
file content (85 lines) | stat: -rw-r--r-- 2,256 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require "helper"

module Neovim
  RSpec.describe Client do
    let(:client) { Support.persistent_client }

    describe "#set_option" do
      it "sets an option from two arguments" do
        expect do
          client.set_option("makeprg", "rake")
        end.to change { client.evaluate("&makeprg") }.to("rake")
      end

      it "sets an option from a string" do
        expect do
          client.set_option("timeoutlen=0")
        end.to change { client.evaluate("&timeoutlen") }.to(0)
      end

      it "sets a boolean option" do
        expect do
          client.set_option("expandtab")
        end.to change { client.evaluate("&expandtab") }.to(1)
      end
    end

    describe "#shutdown" do
      it "causes nvim to exit" do
        client = Neovim.attach_child(Support.child_argv)
        client.shutdown
        expect { client.strwidth("hi") }.to raise_error(Neovim::Session::Disconnected)
      end
    end

    describe "#respond_to?" do
      it "returns true for vim functions" do
        expect(client).to respond_to(:strwidth)
      end

      it "returns true for Ruby functions" do
        expect(client).to respond_to(:inspect)
      end

      it "returns false otherwise" do
        expect(client).not_to respond_to(:foobar)
      end
    end

    describe "#method_missing" do
      it "enables nvim_* function calls" do
        expect(client.strwidth("hi")).to eq(2)
      end

      it "raises exceptions for unknown methods" do
        expect do
          client.foobar
        end.to raise_error(NoMethodError)
      end

      it "raises exceptions for incorrect usage" do
        expect do
          client.strwidth("too", "many")
        end.to raise_error("Wrong number of arguments: expecting 1 but got 2")
      end
    end

    describe "#methods" do
      it "includes builtin methods" do
        expect(client.methods).to include(:inspect)
      end

      it "includes api methods" do
        expect(client.methods).to include(:strwidth)
      end
    end

    describe "#current" do
      it "returns the target" do
        expect(client.current.buffer).to be_a(Buffer)
        expect(client.current.window).to be_a(Window)
        expect(client.current.tabpage).to be_a(Tabpage)
      end
    end
  end
end