Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 145 lines (114 sloc) 2.552 kB
75264d6 @quix initial commit
authored
1
2 require 'prefer'
3 require 'spec'
4
5 module Merb
6 module String
7 def f
8 "Merb::String#f"
9 end
10 end
11
12 module Array
13 def g
14 "Merb::Array#g"
15 end
16 end
17 end
18
19 module Rails
20 module String
21 def f
22 "Rails::String#f"
23 end
24 end
25
26 module Array
27 def g
28 "Rails::Array#g"
29 end
30 end
31 end
32
33 module MerbStuff
34 extend Prefer
35
36 prefer Merb::String => String
37
38 def string_test
39 "".f
40 end
41
42 def string_test_other
43 RailsStuff.string_test
44 end
45
46 extend self
47 end
48
49 module RailsStuff
50 extend Prefer
51
52 prefer Rails::String => String
53
54 def string_test
55 "".f
56 end
57
58 def string_test_other
59 MerbStuff.string_test
60 end
61
62 extend self
63 end
64
65 module Cafeteria
66 extend Prefer
67
68 prefer Rails::String => String, Merb::Array => Array
69
70 def string_test
71 "".f
72 end
73
74 def array_test
75 [].g
76 end
77 end
78
79 def define_main_examples
80 describe RailsStuff do
81 it "should use Rails::String" do
82 Object.new.extend(RailsStuff).string_test.should == "Rails::String#f"
83 end
84 end
85
86 describe MerbStuff do
87 it "should use Merb::String" do
88 Object.new.extend(MerbStuff).string_test.should == "Merb::String#f"
89 end
90 end
91
92 describe Cafeteria do
93 it "should use Rails::String" do
94 Object.new.extend(Cafeteria).string_test.should == "Rails::String#f"
95 end
96
97 it "should use Merb::Array" do
98 Object.new.extend(Cafeteria).array_test.should == "Merb::Array#g"
99 end
100 end
101 end
102
103 describe "When String originally has no mixins," do
104 define_main_examples
105
106 describe "and when outside the scope of a module extended with Prefer" do
107 it "should leave String ancestry untouched" do
108 ancestors = String.ancestors.reject { |ancestor|
109 ancestor.to_s =~ %r!\A(Spec|Quix)::!
110 }
111 ancestors.should == [String, Enumerable, Comparable, Object, Kernel]
112 end
113
114 it "should not add new methods to String" do
115 lambda { "".f }.should raise_error(NoMethodError)
116 end
117 end
118 end
119
120 describe "With Rails::String and Merb::String already mixed into String," do
121 before :all do
122 unless defined?(VISITED)
123 VISITED = true
124 class String
125 include Rails::String
126 include Merb::String
127 end
128 end
129 end
130 define_main_examples
131 end
132
133 describe "Calling RailsStuff from MerbStuff" do
134 it "should use Rails::String" do
135 MerbStuff.string_test_other.should == "Rails::String#f"
136 end
137 end
138
139 describe "Calling MerbStuff from RailsStuff" do
140 it "should use Merb::String" do
141 RailsStuff.string_test_other.should == "Merb::String#f"
142 end
143 end
144
Something went wrong with that request. Please try again.