Skip to content

Commit afed41a

Browse files
committed
update rspec 3
1 parent ca3f053 commit afed41a

File tree

4 files changed

+110
-33
lines changed

4 files changed

+110
-33
lines changed

Gemfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
gem "bundler", ">= 1.7"
4-
gem "rake", "~> 10.2.2"
5-
gem "rspec", "~> 2.14.1"
6-
gem "pry", "~> 0.9.12.6"
7-
gem "simplecov", "~> 0.8.2"
8-
gem "coveralls", "~> 0.7.0", require: false
9-
gem "codeclimate-test-reporter"
10-
gem "ammeter", "~> 1.0.0"
11-
gem "railties"
3+
gem 'bundler', '>= 1.7'
4+
gem 'rake', '~> 10.2.2'
5+
gem 'rspec', '~> 3.1.0'
6+
gem 'guard-rspec', '~> 4.5.0'
7+
gem 'pry', '~> 0.9.12.6'
8+
gem 'simplecov', '~> 0.8.2'
9+
gem 'coveralls', '~> 0.7.0', require: false
10+
gem 'codeclimate-test-reporter'
11+
gem 'ammeter', '~> 1.1.2'
12+
gem 'railties'
1213

1314
# Specify your gem's dependencies in mongoid-observers.gemspec
1415
gemspec

Guardfile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
## Uncomment and set this to only include directories you want to watch
5+
# directories %w(app lib config test spec feature)
6+
7+
## Uncomment to clear the screen before every task
8+
# clearing :on
9+
10+
## Guard internally checks for changes in the Guardfile and exits.
11+
## If you want Guard to automatically start up again, run guard in a
12+
## shell loop, e.g.:
13+
##
14+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
15+
##
16+
## Note: if you are using the `directories` clause above and you are not
17+
## watching the project directory ('.'), the you will want to move the Guardfile
18+
## to a watched dir and symlink it back, e.g.
19+
#
20+
# $ mkdir config
21+
# $ mv Guardfile config/
22+
# $ ln -s config/Guardfile .
23+
#
24+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25+
26+
# Note: The cmd option is now required due to the increasing number of ways
27+
# rspec may be run, below are examples of the most common uses.
28+
# * bundler: 'bundle exec rspec'
29+
# * bundler binstubs: 'bin/rspec'
30+
# * spring: 'bin/rspec' (This will use spring if running and you have
31+
# installed the spring binstubs per the docs)
32+
# * zeus: 'zeus rspec' (requires the server to be started separately)
33+
# * 'just' rspec: 'rspec'
34+
35+
guard :rspec, cmd: "bundle exec rspec" do
36+
require "guard/rspec/dsl"
37+
dsl = Guard::RSpec::Dsl.new(self)
38+
39+
# Feel free to open issues for suggestions and improvements
40+
41+
# RSpec files
42+
rspec = dsl.rspec
43+
watch(rspec.spec_helper) { rspec.spec_dir }
44+
watch(rspec.spec_support) { rspec.spec_dir }
45+
watch(rspec.spec_files)
46+
47+
# Ruby files
48+
ruby = dsl.ruby
49+
dsl.watch_spec_files_for(ruby.lib_files)
50+
51+
# Rails files
52+
rails = dsl.rails(view_extensions: %w(erb haml slim))
53+
dsl.watch_spec_files_for(rails.app_files)
54+
dsl.watch_spec_files_for(rails.views)
55+
56+
watch(rails.controllers) do |m|
57+
[
58+
rspec.spec.("routing/#{m[1]}_routing"),
59+
rspec.spec.("controllers/#{m[1]}_controller"),
60+
rspec.spec.("acceptance/#{m[1]}")
61+
]
62+
end
63+
64+
# Rails config changes
65+
watch(rails.spec_helper) { rspec.spec_dir }
66+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
67+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
68+
69+
# Capybara features specs
70+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
71+
72+
# Turnip features and steps
73+
watch(%r{^spec/acceptance/(.+)\.feature$})
74+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
75+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
76+
end
77+
end

spec/mongoid/observer_spec.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
end
1212

1313
it "is an instance of an active model observer" do
14-
ActorObserver.instance.should be_a_kind_of(ActiveModel::Observer)
14+
expect(ActorObserver.instance).to be_a_kind_of(ActiveModel::Observer)
1515
end
1616

1717
context "when the oberserver observes a different class" do
@@ -27,7 +27,7 @@ class BandObserver < Mongoid::Observer
2727
end
2828

2929
it "returns the proper observed classes" do
30-
BandObserver.observed_classes.should eq([ Record ])
30+
expect(BandObserver.observed_classes).to eq([ Record ])
3131
end
3232
end
3333

@@ -52,7 +52,7 @@ class BandObserver < Mongoid::Observer
5252
end
5353

5454
it "contains the updated value in the observer" do
55-
phone.number_in_observer.should eq("0152-2222-2222")
55+
expect(phone.number_in_observer).to eq("0152-2222-2222")
5656
end
5757
end
5858
end
@@ -68,7 +68,7 @@ class BandObserver < Mongoid::Observer
6868
end
6969

7070
it "observes descendent class" do
71-
observer.last_after_create_record.try(:name).should eq(actress.name)
71+
expect(observer.last_after_create_record.try(:name)).to eq(actress.name)
7272
end
7373
end
7474

@@ -84,7 +84,7 @@ class BandObserver < Mongoid::Observer
8484

8585
it "does not fire the observer" do
8686
Actor.observers.disable(:all) do
87-
actor and observer.last_after_create_record.should_not eq(actor)
87+
actor and expect(observer.last_after_create_record).not_to eq(actor)
8888
end
8989
end
9090
end
@@ -101,7 +101,7 @@ class BandObserver < Mongoid::Observer
101101

102102
it "does not fire the observer" do
103103
Mongoid.observers.disable(:all) do
104-
actor and observer.last_after_create_record.should_not eq(actor)
104+
actor and expect(observer.last_after_create_record).not_to eq(actor)
105105
end
106106
end
107107
end
@@ -113,15 +113,15 @@ class BandObserver < Mongoid::Observer
113113
end
114114

115115
it "observes after initialize" do
116-
recorder.last_callback.should eq(:after_initialize)
116+
expect(recorder.last_callback).to eq(:after_initialize)
117117
end
118118

119119
it "calls after initialize once" do
120-
recorder.call_count[:after_initialize].should eq(1)
120+
expect(recorder.call_count[:after_initialize]).to eq(1)
121121
end
122122

123123
it "contains the model of the callback" do
124-
recorder.last_record[:after_initialize].should eq(actor)
124+
expect(recorder.last_record[:after_initialize]).to eq(actor)
125125
end
126126
end
127127

@@ -139,11 +139,11 @@ class BandObserver < Mongoid::Observer
139139
:around_save ].each do |callback|
140140

141141
it "observes #{callback}" do
142-
recorder.call_count[callback].should eq(1)
142+
expect(recorder.call_count[callback]).to eq(1)
143143
end
144144

145145
it "contains the model of the callback" do
146-
recorder.last_record[callback].should eq(actor)
146+
expect(recorder.last_record[callback]).to eq(actor)
147147
end
148148
end
149149
end
@@ -167,11 +167,11 @@ class BandObserver < Mongoid::Observer
167167
end
168168

169169
it "observes #{callback}" do
170-
recorder.call_count[callback].should eq(1)
170+
expect(recorder.call_count[callback]).to eq(1)
171171
end
172172

173173
it "contains the model of the callback" do
174-
recorder.last_record[callback].should eq(actor)
174+
expect(recorder.last_record[callback]).to eq(actor)
175175
end
176176
end
177177
end
@@ -192,11 +192,11 @@ class BandObserver < Mongoid::Observer
192192
end
193193

194194
it "observes #{callback}" do
195-
recorder.call_count[callback].should eq(1)
195+
expect(recorder.call_count[callback]).to eq(1)
196196
end
197197

198198
it "contains the model of the callback" do
199-
recorder.last_record[callback].should eq(actor)
199+
expect(recorder.last_record[callback]).to eq(actor)
200200
end
201201
end
202202
end
@@ -218,11 +218,11 @@ class BandObserver < Mongoid::Observer
218218
end
219219

220220
it "observes #{callback}" do
221-
recorder.call_count[callback].should eq(1)
221+
expect(recorder.call_count[callback]).to eq(1)
222222
end
223223

224224
it "contains the model of the callback" do
225-
recorder.last_record[callback].should eq(actor)
225+
expect(recorder.last_record[callback]).to eq(actor)
226226
end
227227
end
228228
end
@@ -241,11 +241,11 @@ class BandObserver < Mongoid::Observer
241241
end
242242

243243
it "observes #{callback}" do
244-
recorder.call_count[callback].should eq(1)
244+
expect(recorder.call_count[callback]).to eq(1)
245245
end
246246

247247
it "contains the model of the callback" do
248-
recorder.last_record[callback].should eq(actor)
248+
expect(recorder.last_record[callback]).to eq(actor)
249249
end
250250
end
251251
end
@@ -264,11 +264,11 @@ class BandObserver < Mongoid::Observer
264264
end
265265

266266
it "observes #{callback}" do
267-
recorder.call_count[callback].should eq(1)
267+
expect(recorder.call_count[callback]).to eq(1)
268268
end
269269

270270
it "contains the model of the callback" do
271-
recorder.last_record[callback].should eq(actor)
271+
expect(recorder.last_record[callback]).to eq(actor)
272272
end
273273
end
274274
end
@@ -284,7 +284,7 @@ class BandObserver < Mongoid::Observer
284284
end
285285

286286
it "notifies the observers once" do
287-
actor.after_custom_count.should eq(1)
287+
expect(actor.after_custom_count).to eq(1)
288288
end
289289
end
290290
end

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
RSpec.configure do |config|
3333
config.filter_run focus: true
3434
config.run_all_when_everything_filtered = true
35-
config.treat_symbols_as_metadata_keys_with_true_values = true
3635

3736
config.before(:each) do
3837
Mongoid.purge!

0 commit comments

Comments
 (0)