public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Added an include_the custom RSpec matcher
Now we can say "@post.blog.person.activities.should 
include_the(activity)"
Michael Hartl (author)
Thu May 08 10:54:15 -0700 2008
commit  ecb54f90dd7778d814c2bd09859d32618d349b19
tree    ce517c844277de45b71a60c74f7d5301e1c88bec
parent  36f34ca84b0d217e1d6b4b14a852a7a393fd2622
...
120
121
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
0
@@ -120,5 +120,33 @@
0
     DestroyAssociated.new(attribute)
0
   end
0
   
0
+
0
+ # Return true if an array includes the given attribute.
0
+ # Usage: @person.contacts.should include_the(@contact)
0
+ # N.B. We can't say 'include' instead of 'include_the' because
0
+ # 'include' is a Ruby reserved word.
0
+ class Include
0
+
0
+ def initialize(attribute)
0
+ @attribute = attribute
0
+ end
0
+
0
+ def matches?(object)
0
+ object.include?(@attribute)
0
+ end
0
+
0
+ def failure_message
0
+ "Expected array to include #{@attribute}"
0
+ end
0
+
0
+ def negative_failure_message
0
+ "Expected array not to include #{@attribute}"
0
+ end
0
+ end
0
+
0
+ #
0
+ def include_the(attribute)
0
+ Include.new(attribute)
0
+ end
0
 end
...
40
41
42
43
 
44
45
46
...
59
60
61
62
 
63
64
65
...
40
41
42
 
43
44
45
46
...
59
60
61
 
62
63
64
65
0
@@ -40,7 +40,7 @@
0
     end
0
     
0
     it "should add an activity to the poster" do
0
- @post.blog.person.recent_activity.include?(@activity).should == true
0
+ @post.blog.person.recent_activity.should include_the(@activity)
0
     end
0
   end
0
   
0
@@ -59,7 +59,7 @@
0
     it "should add activities to the poster" do
0
       @post.comments.each do |comment|
0
         activity = Activity.find_by_item_id(comment)
0
- @post.blog.person.activities.include?(activity).should == true
0
+ @post.blog.person.activities.should include_the(activity)
0
       end
0
     end
0
   end
...
33
34
35
36
 
37
38
39
40
...
41
42
43
44
45
 
 
46
47
48
49
 
50
51
52
...
33
34
35
 
36
37
38
39
40
...
41
42
43
 
 
44
45
46
47
48
 
49
50
51
52
0
@@ -33,7 +33,7 @@
0
     
0
       before(:each) do
0
         @comment.save!
0
- @activity = Activity.find_by_item_id(@comment)
0
+ @activity = Activity.find_by_item_id(@comment)
0
       end
0
 
0
       it "should have an activity" do
0
0
@@ -41,12 +41,12 @@
0
       end
0
     
0
       it "should add an activity to the poster" do
0
- @comment.commentable.blog.person.activities.include?(@activity).
0
- should == true
0
+ @comment.commentable.blog.person.activities.
0
+ should include_the(@activity)
0
       end
0
 
0
       it "should add an activity to the commenter" do
0
- @comment.commenter.recent_activity.include?(@activity).should == true
0
+ @comment.commenter.recent_activity.should include_the(@activity)
0
       end
0
     end
0
     
...
33
34
35
36
 
37
38
39
...
33
34
35
 
36
37
38
39
0
@@ -33,7 +33,7 @@
0
     end
0
     
0
     it "should add an activity to the poster" do
0
- @post.person.recent_activity.include?(@activity).should == true
0
+ @post.person.recent_activity.should include_the(@activity)
0
     end
0
   end
0
 end
...
37
38
39
40
 
41
42
43
...
37
38
39
 
40
41
42
43
0
@@ -37,7 +37,7 @@
0
     it "should log an activity if description changed" do
0
       @person.update_attributes(:description => "New Description")
0
       activity = Activity.find_by_item_id(@person)
0
- Activity.global_feed.include?(activity).should == true
0
+ Activity.global_feed.should include_the(activity)
0
     end
0
     
0
     it "should not log an activity if description didn't change" do

Comments

    No one has commented yet.