File: instance_methods_spec.rb

package info (click to toggle)
ruby-bogus 0.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: ruby: 4,237; makefile: 8; sh: 2
file content (45 lines) | stat: -rw-r--r-- 919 bytes parent folder | download | duplicates (4)
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
require 'spec_helper'

module Bogus
  describe InstanceMethods do
    class SampleClass
      def foo(bar)
      end

      def hello
      end

      def self.bar(bam)
      end
    end

    let(:instance_methods) { InstanceMethods.new(SampleClass) }

    it "lists the instance methods" do
      expect(instance_methods.all).to match_array([:foo, :hello])
    end

    it "returns the instance methods by name" do
      expect(instance_methods.get(:foo)).to eq(
        SampleClass.instance_method(:foo))
    end

    it "removes methods by name" do
      instance_methods.remove(:hello)

      expect(SampleClass.new).to_not respond_to(:hello)
    end

    it "defines instance methods" do
      instance_methods.define <<-EOF
      def greet(name)
        return "Hello, " + name + "!"
      end
      EOF

      instance = SampleClass.new

      expect(instance.greet("Joe")).to eq "Hello, Joe!"
    end
  end
end