File: try_call_spec.rb

package info (click to toggle)
ruby-extlib 0.9.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 576 kB
  • sloc: ruby: 7,014; makefile: 5
file content (74 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'
require 'extlib'

describe "#try_call" do
  describe "with an Object" do
    before :all do
      @receiver = Object.new
    end

    it "returns receiver itself" do
      @receiver.try_call.should == @receiver
    end
  end

  describe "with a number" do
    before :all do
      @receiver = 42
    end

    it "returns receiver itself" do
      @receiver.try_call.should == @receiver
    end
  end

  describe "with a String" do
    before :all do
      @receiver = "Ruby, programmer's best friend"
    end

    it "returns receiver itself" do
      @receiver.try_call.should == @receiver
    end
  end

  describe "with a hash" do
    before :all do
      @receiver = { :functional_programming => "FTW" }
    end

    it "returns receiver itself" do
      @receiver.try_call.should == @receiver
    end
  end

  describe "with a Proc" do
    before :all do
      @receiver = Proc.new { 5 * 7 }
    end

    it "returns result of calling of a proc" do
      @receiver.try_call.should == 35
    end
  end

  describe "with a Proc that takes 2 arguments" do
    before :all do
      @receiver = Proc.new { |one, other| one + other }
    end

    it "passes arguments to #call, returns result of calling of a proc" do
      @receiver.try_call(10, 20).should == 30
    end
  end

  describe "with a Proc that takes 3 arguments" do
    before :all do
      @receiver = Proc.new { |a, b, c| (a + b) * c }
    end

    it "passes arguments to #call, returns result of calling of a proc" do
      @receiver.try_call(10, 20, 3).should == 90
    end
  end
end