File tree 3 files changed +57
-4
lines changed
3 files changed +57
-4
lines changed Original file line number Diff line number Diff line change 3
3
4
4
gem 'rake'
5
5
6
- gem 'rspec' , '3.0.0.beta1'
7
- gem 'rspec-support' , '3.0.0.beta1'
8
- gem 'rspec-core' , '3.0.0.beta1'
6
+ gem 'opal' , :github => 'opal/opal'
7
+
8
+ gem 'rspec' , '3.0.0.beta1'
9
+ gem 'rspec-support' , '3.0.0.beta1'
10
+ gem 'rspec-core' , '3.0.0.beta1'
11
+ gem 'rspec-mocks' , '3.0.0.beta1'
9
12
gem 'rspec-expectations' , '3.0.0.beta1'
10
- gem 'rspec-mocks' , '3.0.0.beta1'
Original file line number Diff line number Diff line change @@ -62,3 +62,17 @@ def self.disambiguate(name, const_scope)
62
62
name
63
63
end
64
64
end
65
+
66
+ # Opal does not support ObjectSpace, so force object __id__'s
67
+ class RSpec ::Mocks ::Space
68
+ def id_for ( object )
69
+ object . __id__
70
+ end
71
+ end
72
+
73
+ # Buggy under Opal?
74
+ class RSpec ::Mocks ::MethodDouble
75
+ def save_original_method!
76
+ @original_method ||= @method_stasher . original_method
77
+ end
78
+ end
Original file line number Diff line number Diff line change
1
+ describe "RSpec mocks" do
2
+ describe "stubs" do
3
+ it "can stub basic methods" do
4
+ obj = Object . new
5
+ expect ( obj ) . to receive ( :foo ) { 100 }
6
+ obj . foo . should == 100
7
+ end
8
+
9
+ it "raises an exception when stub returns wrong value" do
10
+ expect {
11
+ obj = Object . new
12
+ expect ( obj ) . to receive ( :bar ) { 400 }
13
+ obj . bar . should == 42
14
+ } . to raise_error ( Exception )
15
+ end
16
+ end
17
+
18
+ describe "doubles" do
19
+ it "define methods on double" do
20
+ person = double ( "person" , :name => "Adam" )
21
+ expect ( person . name ) . to eq ( "Adam" )
22
+ end
23
+
24
+ it "once" do
25
+ person = double ( "person" )
26
+ expect ( person ) . to receive ( :name ) . once
27
+ person . name . should eq ( nil )
28
+ end
29
+
30
+ it "twice" do
31
+ person = double ( "person" )
32
+ expect ( person ) . to receive ( :name ) . twice
33
+ person . name
34
+ person . name
35
+ end
36
+ end
37
+ end
You can’t perform that action at this time.
0 commit comments