Skip to content

Commit af12dc4

Browse files
committed
Merge pull request #703 from projecthydra/byebye_shoulds
Convert specs to RSpec 3.1.7 syntax with Transpec. Fixes #702
2 parents c2c8467 + ecac643 commit af12dc4

File tree

103 files changed

+1011
-988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1011
-988
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
describe AuthoritiesController do
3+
describe AuthoritiesController, :type => :controller do
44
describe "#query" do
55
it "should return an array of hashes" do
66
mock_hits = [{label: "English", uri: "http://example.org/eng"},
@@ -9,12 +9,12 @@
99
{label: "Edgar", uri: "http://example.org/edga"},
1010
{label: "Eddie", uri: "http://example.org/edd"},
1111
{label: "Economics", uri: "http://example.org/eco"}]
12-
LocalAuthority.should_receive(:entries_by_term).and_return(mock_hits)
12+
expect(LocalAuthority).to receive(:entries_by_term).and_return(mock_hits)
1313
xhr :get, :query, model: "generic_files", term: "subject", q: "E"
14-
response.should be_success
15-
JSON.parse(response.body).count.should == 6
16-
JSON.parse(response.body)[0]["label"].should == "English"
17-
JSON.parse(response.body)[0]["uri"].should == "http://example.org/eng"
14+
expect(response).to be_success
15+
expect(JSON.parse(response.body).count).to eq(6)
16+
expect(JSON.parse(response.body)[0]["label"]).to eq("English")
17+
expect(JSON.parse(response.body)[0]["uri"]).to eq("http://example.org/eng")
1818
end
1919
end
2020
end

spec/controllers/batch_controller_spec.rb

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'spec_helper'
22

3-
describe BatchController do
3+
describe BatchController, :type => :controller do
44
before do
5-
controller.stub(:has_access?).and_return(true)
5+
allow(controller).to receive(:has_access?).and_return(true)
66
@user = FactoryGirl.find_or_create(:jill)
77
sign_in @user
8-
User.any_instance.stub(:groups).and_return([])
9-
controller.stub(:clear_session_user) ## Don't clear out the authenticated session
8+
allow_any_instance_of(User).to receive(:groups).and_return([])
9+
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
1010
end
1111
after do
1212
@user.delete
@@ -35,82 +35,82 @@
3535
it "should enqueue a batch update job" do
3636
params = {'generic_file' => {'read_groups_string' => '', 'read_users_string' => 'archivist1, archivist2', 'tag' => ['']}, 'id' => @batch.pid, 'controller' => 'batch', 'action' => 'update'}
3737
s1 = double('one')
38-
BatchUpdateJob.should_receive(:new).with(@user.user_key, params).and_return(s1)
39-
Sufia.queue.should_receive(:push).with(s1).once
38+
expect(BatchUpdateJob).to receive(:new).with(@user.user_key, params).and_return(s1)
39+
expect(Sufia.queue).to receive(:push).with(s1).once
4040
post :update, id: @batch.pid, "generic_file" => {"read_groups_string" => "", "read_users_string" => "archivist1, archivist2", "tag" => [""]}
4141
end
4242
it "should show flash messages" do
4343
post :update, id: @batch.pid, "generic_file" => {"read_groups_string" => "","read_users_string" => "archivist1, archivist2", "tag" => [""]}
44-
response.should redirect_to @routes.url_helpers.dashboard_files_path
45-
flash[:notice].should_not be_nil
46-
flash[:notice].should_not be_empty
47-
flash[:notice].should include("Your files are being processed")
44+
expect(response).to redirect_to @routes.url_helpers.dashboard_files_path
45+
expect(flash[:notice]).not_to be_nil
46+
expect(flash[:notice]).not_to be_empty
47+
expect(flash[:notice]).to include("Your files are being processed")
4848
end
4949

5050
describe "when user has edit permissions on a file" do
5151
it "should set the groups" do
5252
post :update, id: @batch.pid, "generic_file"=>{"permissions"=>{"group"=>{"public"=>"1", "registered"=>"2"}}}
53-
@file.reload.read_groups.should == []
54-
@file.reload.edit_groups.should == []
55-
response.should redirect_to @routes.url_helpers.dashboard_files_path
53+
expect(@file.reload.read_groups).to eq([])
54+
expect(@file.reload.edit_groups).to eq([])
55+
expect(response).to redirect_to @routes.url_helpers.dashboard_files_path
5656
end
5757

5858
it "should set the users with read access" do
5959
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"archivist1, archivist2", "tag"=>[""]}
6060
file = GenericFile.find(@file.pid)
61-
file.read_users.should == ['archivist1', 'archivist2']
61+
expect(file.read_users).to eq(['archivist1', 'archivist2'])
6262

63-
response.should redirect_to @routes.url_helpers.dashboard_files_path
63+
expect(response).to redirect_to @routes.url_helpers.dashboard_files_path
6464
end
6565
it "should set the groups with read access" do
6666
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
6767
file = GenericFile.find(@file.pid)
68-
file.read_groups.should == ['group1', 'group2']
68+
expect(file.read_groups).to eq(['group1', 'group2'])
6969
end
7070
it "should set public read access" do
7171
post :update, id: @batch.pid, "visibility"=>"open", "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"", "tag"=>[""]}
7272
file = GenericFile.find(@file.pid)
73-
file.read_groups.should == ['public']
73+
expect(file.read_groups).to eq(['public'])
7474
end
7575
it "should set public read access and groups at the same time" do
7676
post :update, id: @batch.pid, "visibility"=>"open", "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
7777
file = GenericFile.find(@file.pid)
78-
file.read_groups.should == ['group1', 'group2', 'public']
78+
expect(file.read_groups).to eq(['group1', 'group2', 'public'])
7979
end
8080
it "should set public discover access and groups at the same time" do
8181
post :update, id: @batch.pid, "permission"=>{"group"=>{"public"=>"none"}}, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
8282
file = GenericFile.find(@file.pid)
83-
file.read_groups.should == ['group1', 'group2']
84-
file.discover_groups.should == []
83+
expect(file.read_groups).to eq(['group1', 'group2'])
84+
expect(file.discover_groups).to eq([])
8585
end
8686
it "should set metadata like title" do
8787
post :update, id: @batch.pid, "generic_file"=>{"tag"=>["footag", "bartag"]}, "title"=>{@file.pid=>["New Title"]}
8888
file = GenericFile.find(@file.pid)
89-
file.title.should == ["New Title"]
90-
file.tag.should == ["footag", "bartag"]
89+
expect(file.title).to eq(["New Title"])
90+
expect(file.tag).to eq(["footag", "bartag"])
9191
end
9292
it "should not set any tags" do
9393
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"archivist1", "tag"=>[""]}
9494
file = GenericFile.find(@file.pid)
95-
file.tag.should be_empty
95+
expect(file.tag).to be_empty
9696
end
9797
end
9898
describe "when user does not have edit permissions on a file" do
9999
it "should not modify the object" do
100100
file = GenericFile.find(@file2.pid)
101101
file.title = ["Original Title"]
102-
file.read_groups.should == []
102+
expect(file.read_groups).to eq([])
103103
file.save
104104
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}, "title"=>{@file2.pid=>["Title Wont Change"]}
105105
file = GenericFile.find(@file2.pid)
106-
file.title.should == ["Original Title"]
107-
file.read_groups.should == []
106+
expect(file.title).to eq(["Original Title"])
107+
expect(file.read_groups).to eq([])
108108
end
109109
end
110110
end
111111
describe "#edit" do
112112
before do
113-
User.any_instance.stub(:display_name).and_return("Jill Z. User")
113+
allow_any_instance_of(User).to receive(:display_name).and_return("Jill Z. User")
114114
@b1 = Batch.new
115115
@b1.save
116116
@file = GenericFile.new(batch: @b1, label: 'f1')
@@ -127,8 +127,8 @@
127127
end
128128
it "should default creator" do
129129
get :edit, id: @b1.id
130-
assigns[:generic_file].creator[0].should == @user.display_name
131-
assigns[:generic_file].title[0].should == 'f1'
130+
expect(assigns[:generic_file].creator[0]).to eq(@user.display_name)
131+
expect(assigns[:generic_file].title[0]).to eq('f1')
132132
end
133133
end
134134
end

spec/controllers/batch_edits_controller_spec.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'spec_helper'
22

3-
describe BatchEditsController do
3+
describe BatchEditsController, :type => :controller do
44
before do
5-
controller.stub(:has_access?).and_return(true)
5+
allow(controller).to receive(:has_access?).and_return(true)
66
@user = FactoryGirl.find_or_create(:jill)
77
sign_in @user
8-
User.any_instance.stub(:groups).and_return([])
9-
controller.stub(:clear_session_user) ## Don't clear out the authenticated session
8+
allow_any_instance_of(User).to receive(:groups).and_return([])
9+
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
1010
request.env["HTTP_REFERER"] = 'test.host/original_page'
1111
end
1212

@@ -26,9 +26,9 @@
2626
end
2727
it "should be successful" do
2828
get :edit
29-
response.should be_successful
30-
assigns[:terms].should == [:creator, :contributor, :description, :tag, :rights, :publisher,
31-
:date_created, :subject, :language, :identifier, :based_near, :related_url]
29+
expect(response).to be_successful
30+
expect(assigns[:terms]).to eq([:creator, :contributor, :description, :tag, :rights, :publisher,
31+
:date_created, :subject, :language, :identifier, :based_near, :related_url])
3232
expect(assigns[:show_file].creator).to eq ["Fred", "Wilma"]
3333
expect(assigns[:show_file].publisher).to eq ["Rand McNally"]
3434
expect(assigns[:show_file].language).to eq ["en"]

spec/controllers/catalog_controller_spec.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
describe CatalogController do
3+
describe CatalogController, :type => :controller do
44
routes { Rails.application.class.routes }
55

66
let(:user) { @user }
@@ -38,19 +38,19 @@
3838
get :index, q: 'full_textfull_text'
3939
expect(response).to be_success
4040
expect(response).to render_template('catalog/index')
41-
assigns(:document_list).count.should eql(1)
42-
assigns(:document_list).map(&:id).should == [@gf2.id]
41+
expect(assigns(:document_list).count).to eql(1)
42+
expect(assigns(:document_list).map(&:id)).to eq([@gf2.id])
4343
end
4444
end
4545

4646
describe "term search" do
4747
it "should find records" do
4848
get :index, q: "pdf", owner: 'all'
4949
expect(response).to be_success
50-
response.should render_template('catalog/index')
51-
assigns(:document_list).map(&:id).should == [@gf1.id]
52-
assigns(:document_list).count.should eql(1)
53-
assigns(:document_list).first['desc_metadata__title_tesim'].should == ['Test Document PDF']
50+
expect(response).to render_template('catalog/index')
51+
expect(assigns(:document_list).map(&:id)).to eq([@gf1.id])
52+
expect(assigns(:document_list).count).to eql(1)
53+
expect(assigns(:document_list).first['desc_metadata__title_tesim']).to eq(['Test Document PDF'])
5454
end
5555
end
5656

@@ -61,8 +61,8 @@
6161
end
6262
it "should find facet files" do
6363
expect(response).to be_success
64-
response.should render_template('catalog/index')
65-
assigns(:document_list).count.should eql(1)
64+
expect(response).to render_template('catalog/index')
65+
expect(assigns(:document_list).count).to eql(1)
6666
end
6767
end
6868

spec/controllers/collections_controller_spec.rb

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'spec_helper'
22

3-
describe CollectionsController do
3+
describe CollectionsController, :type => :controller do
44
before(:each) { @routes = Hydra::Collections::Engine.routes }
55
before do
6-
controller.stub(:has_access?).and_return(true)
7-
User.any_instance.stub(:groups).and_return([])
6+
allow(controller).to receive(:has_access?).and_return(true)
7+
allow_any_instance_of(User).to receive(:groups).and_return([])
88
end
99

1010
let(:user) { FactoryGirl.create(:user) }
@@ -22,7 +22,7 @@
2222

2323
it 'should assign @collection' do
2424
get :new
25-
assigns(:collection).should be_kind_of(Collection)
25+
expect(assigns(:collection)).to be_kind_of(Collection)
2626
end
2727
end
2828

@@ -32,10 +32,10 @@
3232
end
3333

3434
it "should create a Collection" do
35-
controller.should_receive(:has_access?).and_return(true)
35+
expect(controller).to receive(:has_access?).and_return(true)
3636
old_count = Collection.count
3737
post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
38-
Collection.count.should == old_count+1
38+
expect(Collection.count).to eq(old_count+1)
3939
end
4040
it "should create a Collection with files I can access" do
4141
@asset1 = GenericFile.new(title: ["First of the Assets"])
@@ -47,15 +47,15 @@
4747
@asset3 = GenericFile.new(title: ["Third of the Assets"], depositor:'abc')
4848
@asset3.apply_depositor_metadata('abc')
4949
@asset3.save
50-
controller.should_receive(:has_access?).and_return(true)
50+
expect(controller).to receive(:has_access?).and_return(true)
5151
old_count = Collection.count
5252
post :create, collection: { title: "My own Collection", description: "The Description\r\n\r\nand more" },
5353
batch_document_ids: [@asset1.id, @asset2.id, @asset3.id]
54-
Collection.count.should == old_count+1
54+
expect(Collection.count).to eq(old_count+1)
5555
collection = assigns(:collection)
56-
collection.members.should include (@asset1)
57-
collection.members.should include (@asset2)
58-
collection.members.to_a.should_not include (@asset3) # .to_a to avoid a call to any? which doesn't exist in AF::HABTM
56+
expect(collection.members).to include (@asset1)
57+
expect(collection.members).to include (@asset2)
58+
expect(collection.members.to_a).not_to include (@asset3) # .to_a to avoid a call to any? which doesn't exist in AF::HABTM
5959
@asset1.destroy
6060
@asset2.destroy
6161
@asset3.destroy
@@ -67,13 +67,13 @@
6767
@asset1.save
6868
post :create, batch_document_ids: [@asset1.id],
6969
collection: { title: "My Secong Collection ", description: "The Description\r\n\r\nand more" }
70-
assigns[:collection].members.should == [@asset1]
70+
expect(assigns[:collection].members).to eq([@asset1])
7171
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
72-
asset_results["response"]["numFound"].should == 1
72+
expect(asset_results["response"]["numFound"]).to eq(1)
7373
doc = asset_results["response"]["docs"].first
74-
doc["id"].should == @asset1.id
74+
expect(doc["id"]).to eq(@asset1.id)
7575
afterupdate = GenericFile.find(@asset1.pid)
76-
doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
76+
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
7777
end
7878

7979
end
@@ -103,21 +103,21 @@
103103

104104
it "should set collection on members" do
105105
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids: [@asset3.pid, @asset1.pid, @asset2.pid]
106-
response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.noid)
107-
assigns[:collection].members.map{|m| m.pid}.sort.should == [@asset2, @asset3, @asset1].map {|m| m.pid}.sort
106+
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.noid)
107+
expect(assigns[:collection].members.map{|m| m.pid}.sort).to eq([@asset2, @asset3, @asset1].map {|m| m.pid}.sort)
108108
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
109-
asset_results["response"]["numFound"].should == 1
109+
expect(asset_results["response"]["numFound"]).to eq(1)
110110
doc = asset_results["response"]["docs"].first
111-
doc["id"].should == @asset2.id
111+
expect(doc["id"]).to eq(@asset2.id)
112112
afterupdate = GenericFile.find(@asset2.pid)
113-
doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
113+
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
114114
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids: [@asset2]
115115
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
116-
asset_results["response"]["numFound"].should == 1
116+
expect(asset_results["response"]["numFound"]).to eq(1)
117117
doc = asset_results["response"]["docs"].first
118-
doc["id"].should == @asset2.pid
118+
expect(doc["id"]).to eq(@asset2.pid)
119119
afterupdate = GenericFile.find(@asset2.pid)
120-
doc[Solrizer.solr_name(:collection)].should be_nil
120+
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
121121
end
122122
end
123123

@@ -141,8 +141,8 @@
141141
@collection.apply_depositor_metadata(user.user_key)
142142
@collection.members = [@asset1,@asset2,@asset3]
143143
@collection.save!
144-
controller.stub(:authorize!).and_return(true)
145-
controller.stub(:apply_gated_search)
144+
allow(controller).to receive(:authorize!).and_return(true)
145+
allow(controller).to receive(:apply_gated_search)
146146
end
147147
context "when signed in" do
148148
before do
@@ -152,7 +152,7 @@
152152
it "should return the collection and its members" do
153153
get :show, id: @collection.id
154154
expect(response).to be_successful
155-
assigns[:collection].title.should == @collection.title
155+
expect(assigns[:collection].title).to eq(@collection.title)
156156
ids = assigns[:member_docs].map(&:id)
157157
expect(ids).to include @asset1.pid, @asset2.pid, @asset3.pid
158158
expect(ids).to_not include @asset4.pid
@@ -165,7 +165,7 @@
165165
context "not signed in" do
166166
it "should not show me files in the collection" do
167167
get :show, id: @collection.id
168-
assigns[:member_docs].count.should == 0
168+
expect(assigns[:member_docs].count).to eq(0)
169169
end
170170
end
171171
end
@@ -179,7 +179,7 @@
179179
end
180180
it "should not show flash" do
181181
get :edit, id: @collection.id
182-
flash[:notice].should be_nil
182+
expect(flash[:notice]).to be_nil
183183
end
184184
end
185185
end

spec/controllers/content_blocks_controller_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
describe ContentBlocksController do
3+
describe ContentBlocksController, :type => :controller do
44
describe "#update" do
55
let(:content_block) { FactoryGirl.create(:content_block) }
66
before { request.env["HTTP_REFERER"] = "whence_i_came" }
@@ -14,10 +14,10 @@
1414

1515
context "when logged in" do
1616
let(:user) { FactoryGirl.create(:user) }
17-
before { controller.stub(current_user: user) }
17+
before { allow(controller).to receive_messages(current_user: user) }
1818

1919
context "as a user in the admin group" do
20-
before { user.should_receive(:groups).and_return( ['admin', 'registered']) }
20+
before { expect(user).to receive(:groups).and_return( ['admin', 'registered']) }
2121

2222
it "should save" do
2323
patch :update, id: content_block, content_block: { value: 'foo' }

0 commit comments

Comments
 (0)