diff --git a/Gemfile b/Gemfile index a36a8ced5e454dedbac605a7aa248753b73a6c7b..2413d544aee3c7f700e6060beb78f55b0e1db89a 100644 --- a/Gemfile +++ b/Gemfile @@ -192,7 +192,7 @@ group :test do # RSpec (unit tests, some integration tests) gem 'fixture_builder', '0.3.6' - gem 'fuubar', '1.3.3' + gem 'fuubar', '2.0.0' gem 'rspec-instafail', '0.2.5', :require => false gem 'test_after_commit', '0.2.5' @@ -212,7 +212,7 @@ end group :development, :test do # RSpec (unit tests, some integration tests) - gem 'rspec-rails', '2.99' + gem 'rspec-rails', '3.0.0' # Cucumber (integration tests) gem 'cucumber-rails', '1.4.1', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 861d8ae6e85127f6f1361e000404dd15d6e3fed8..9b55ad4667f6c81bfeadb09fe33cf94aa62695e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -181,8 +181,8 @@ GEM thor (>= 0.13.6) formatador (0.2.5) fssm (0.2.10) - fuubar (1.3.3) - rspec (>= 2.14.0, < 3.1.0) + fuubar (2.0.0) + rspec (~> 3.0) ruby-progressbar (~> 1.4) gherkin (2.12.2) multi_json (~> 1.3) @@ -392,27 +392,28 @@ GEM roxml (3.1.6) activesupport (>= 2.3.0) nokogiri (>= 1.3.3) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-collection_matchers (1.0.0) - rspec-expectations (>= 2.99.0.beta1) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) + rspec (3.0.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-core (3.0.4) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) rspec-instafail (0.2.5) rspec - rspec-mocks (2.99.2) - rspec-rails (2.99.0) + rspec-mocks (3.0.4) + rspec-support (~> 3.0.0) + rspec-rails (3.0.0) actionpack (>= 3.0) - activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-collection_matchers - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.4) ruby-oembed (0.8.10) ruby-progressbar (1.5.1) rubyzip (1.1.6) @@ -527,7 +528,7 @@ DEPENDENCIES fog (= 1.23.0) foreigner (= 1.6.1) foreman (= 0.62) - fuubar (= 1.3.3) + fuubar (= 2.0.0) gon (= 5.1.2) guard-cucumber (= 1.4.1) guard-rspec (= 4.3.1) @@ -571,7 +572,7 @@ DEPENDENCIES remotipart (= 1.2.1) roxml (= 3.1.6) rspec-instafail (= 0.2.5) - rspec-rails (= 2.99) + rspec-rails (= 3.0.0) ruby-oembed (= 0.8.10) sass-rails (= 4.0.3) selenium-webdriver (= 2.42.0) diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index dcb59d04ed5905247bc9d23c33b9aaf240a70d1c..dc238d51ad03c39dc54d13f7ccd7aa21fa1b9926 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe Admin::UsersController do +describe Admin::UsersController, :type => :controller do before do @user = FactoryGirl.create :user Role.add_admin(@user.person) @@ -12,8 +12,8 @@ describe Admin::UsersController do describe '#close_account' do it 'queues a job to disable the given account' do other_user = FactoryGirl.create :user - other_user.should_receive(:close_account!) - User.stub(:find).and_return(other_user) + expect(other_user).to receive(:close_account!) + allow(User).to receive(:find).and_return(other_user) post :close_account, id: other_user.id end diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index 398b7b5ebf2b58220ee8621f457262543e3b8c91..3bab4f38a114bddc38b0e7396b81bd7901481d5e 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe AdminsController do +describe AdminsController, :type => :controller do before do @user = FactoryGirl.create :user sign_in :user, @user @@ -14,7 +14,7 @@ describe AdminsController do context 'admin not signed in' do it 'is behind redirect_unless_admin' do get :user_search - response.should redirect_to stream_path + expect(response).to redirect_to stream_path end end @@ -25,23 +25,23 @@ describe AdminsController do it 'succeeds and renders user_search' do get :user_search - response.should be_success - response.should render_template(:user_search) + expect(response).to be_success + expect(response).to render_template(:user_search) end it 'assigns users to an empty array if nothing is searched for' do get :user_search - assigns[:users].should == [] + expect(assigns[:users]).to eq([]) end it 'searches on username' do get :user_search, admins_controller_user_search: { username: @user.username } - assigns[:users].should == [@user] + expect(assigns[:users]).to eq([@user]) end it 'searches on email' do get :user_search, admins_controller_user_search: { email: @user.email } - assigns[:users].should == [@user] + expect(assigns[:users]).to eq([@user]) end it 'searches on age < 13 (COPPA)' do @@ -55,8 +55,8 @@ describe AdminsController do get :user_search, admins_controller_user_search: { under13: '1' } - assigns[:users].should include(u_13) - assigns[:users].should_not include(o_13) + expect(assigns[:users]).to include(u_13) + expect(assigns[:users]).not_to include(o_13) end end end @@ -65,7 +65,7 @@ describe AdminsController do context 'admin not signed in' do it 'is behind redirect_unless_admin' do get :admin_inviter - response.should redirect_to stream_path + expect(response).to redirect_to stream_path end end @@ -77,14 +77,14 @@ describe AdminsController do it 'does not die if you do it twice' do get :admin_inviter, :identifier => 'bob@moms.com' get :admin_inviter, :identifier => 'bob@moms.com' - response.should be_redirect + expect(response).to be_redirect end it 'invites a new user' do - EmailInviter.should_receive(:new).and_return(double.as_null_object) + expect(EmailInviter).to receive(:new).and_return(double.as_null_object) get :admin_inviter, :identifier => 'bob@moms.com' - response.should redirect_to user_search_path - flash.notice.should include("invitation sent") + expect(response).to redirect_to user_search_path + expect(flash.notice).to include("invitation sent") end end end @@ -96,8 +96,8 @@ describe AdminsController do it 'succeeds and renders stats' do get :stats - response.should be_success - response.should render_template(:stats) + expect(response).to be_success + expect(response).to render_template(:stats) end end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index eda989f2c94fae67c4c3b43606a0c6d72b4bdaec..1b2e44ff3190e67f4442433bf28b85d377fefc7e 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ApplicationController do +describe ApplicationController, :type => :controller do controller do def index head :ok @@ -18,20 +18,20 @@ describe ApplicationController do describe '#set_diaspora_headers' do it 'sets the version header' do get :index - response.headers['X-Diaspora-Version'].should include AppConfig.version.number.get + expect(response.headers['X-Diaspora-Version']).to include AppConfig.version.number.get end context 'with git info' do before do - AppConfig.stub(:git_available?).and_return(true) - AppConfig.stub(:git_update).and_return('yesterday') - AppConfig.stub(:git_revision).and_return('02395') + allow(AppConfig).to receive(:git_available?).and_return(true) + allow(AppConfig).to receive(:git_update).and_return('yesterday') + allow(AppConfig).to receive(:git_revision).and_return('02395') end it 'sets the git header' do get :index - response.headers['X-Git-Update'].should == 'yesterday' - response.headers['X-Git-Revision'].should == '02395' + expect(response.headers['X-Git-Update']).to eq('yesterday') + expect(response.headers['X-Git-Revision']).to eq('02395') end end end @@ -41,25 +41,25 @@ describe ApplicationController do request.format = :html session[:mobile_view] = true get :index - request.format.mobile?.should be true + expect(request.format.mobile?).to be true end it 'uses :html for :tablets' do request.format = :tablet session[:tablet_view] = true get :index - request.format.html?.should be true + expect(request.format.html?).to be true end it "doesn't mess up other formats, like json" do get :index, :format => 'json' - request.format.json?.should be true + expect(request.format.json?).to be true end it "doesn't mess up other formats, like xml, even with :mobile session" do session[:mobile_view] = true get :index, :format => 'xml' - request.format.xml?.should be true + expect(request.format.xml?).to be true end end @@ -70,11 +70,11 @@ describe ApplicationController do end it 'queries current_users tag if there are tag_followings' do - @controller.send(:tags).should == [@tag] + expect(@controller.send(:tags)).to eq([@tag]) end it 'does not query twice' do - User.any_instance.should_receive(:followed_tags).once.and_return([@tag]) + expect_any_instance_of(User).to receive(:followed_tags).once.and_return([@tag]) @controller.send(:tags) @controller.send(:tags) end @@ -87,7 +87,7 @@ describe ApplicationController do end it "redirects to getting started if the user has getting started set to true" do - @controller.send(:after_sign_in_path_for, alice).should == getting_started_path + expect(@controller.send(:after_sign_in_path_for, alice)).to eq(getting_started_path) end end end diff --git a/spec/controllers/aspect_memberships_controller_spec.rb b/spec/controllers/aspect_memberships_controller_spec.rb index 91a1b5c1ff43358cf185bfb686b67d4afb50a1e6..0a5e125e909f93b4e0f7a124dda0638f26f2a6b0 100644 --- a/spec/controllers/aspect_memberships_controller_spec.rb +++ b/spec/controllers/aspect_memberships_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe AspectMembershipsController do +describe AspectMembershipsController, :type => :controller do before do @aspect0 = alice.aspects.first @aspect1 = alice.aspects.create(:name => "another aspect") @@ -14,7 +14,7 @@ describe AspectMembershipsController do alice.getting_started = false alice.save sign_in :user, alice - @controller.stub(:current_user).and_return(alice) + allow(@controller).to receive(:current_user).and_return(alice) request.env["HTTP_REFERER"] = 'http://' + request.host end @@ -28,16 +28,16 @@ describe AspectMembershipsController do :format => :json, :person_id => bob.person.id, :aspect_id => @aspect1.id - response.should be_success + expect(response).to be_success end it 'creates an aspect membership' do - lambda { + expect { post :create, :format => :json, :person_id => bob.person.id, :aspect_id => @aspect1.id - }.should change{ + }.to change{ alice.contact_for(bob.person).aspect_memberships.count }.by(1) end @@ -45,30 +45,30 @@ describe AspectMembershipsController do it 'creates a contact' do #argggg why? alice.contacts.reload - lambda { + expect { post :create, :format => :json, :person_id => @person.id, :aspect_id => @aspect0.id - }.should change{ + }.to change{ alice.contacts.size }.by(1) end it 'failure flashes error' do - alice.should_receive(:share_with).and_return(nil) + expect(alice).to receive(:share_with).and_return(nil) post :create, :format => :json, :person_id => @person.id, :aspect_id => @aspect0.id - flash[:error].should_not be_blank + expect(flash[:error]).not_to be_blank end it 'does not 500 on a duplicate key error' do params = {:format => :json, :person_id => @person.id, :aspect_id => @aspect0.id} post :create, params post :create, params - response.status.should == 400 + expect(response.status).to eq(400) end context 'json' do @@ -79,7 +79,7 @@ describe AspectMembershipsController do :aspect_id => @aspect0.id contact = @controller.current_user.contact_for(@person) - response.body.should == contact.aspect_memberships.first.to_json + expect(response.body).to eq(contact.aspect_memberships.first.to_json) end end end @@ -88,23 +88,23 @@ describe AspectMembershipsController do it 'removes contacts from an aspect' do membership = alice.add_contact_to_aspect(@contact, @aspect1) delete :destroy, :format => :json, :id => membership.id - response.should be_success + expect(response).to be_success @aspect1.reload - @aspect1.contacts.to_a.should_not include @contact + expect(@aspect1.contacts.to_a).not_to include @contact end it 'does not 500 on an html request' do membership = alice.add_contact_to_aspect(@contact, @aspect1) delete :destroy, :id => membership.id - response.should redirect_to :back + expect(response).to redirect_to :back @aspect1.reload - @aspect1.contacts.to_a.should_not include @contact + expect(@aspect1.contacts.to_a).not_to include @contact end it 'aspect membership does not exist' do delete :destroy, :format => :json, :id => 123 - response.should_not be_success - response.body.should include "Could not find the selected person in that aspect" + expect(response).not_to be_success + expect(response.body).to include "Could not find the selected person in that aspect" end end end diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 42cec0058a043a5ca9f0e665aa90af657ede27c5..4a13f4591d5277d0fde1495e86c5a0bec4808ebd 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe AspectsController do +describe AspectsController, :type => :controller do before do alice.getting_started = false alice.save @@ -12,7 +12,7 @@ describe AspectsController do @alices_aspect_1 = alice.aspects.where(:name => "generic").first @alices_aspect_2 = alice.aspects.create(:name => "another aspect") - @controller.stub(:current_user).and_return(alice) + allow(@controller).to receive(:current_user).and_return(alice) request.env["HTTP_REFERER"] = 'http://' + request.host end @@ -20,74 +20,74 @@ describe AspectsController do describe "#new" do it "renders a remote form if remote is true" do get :new, "remote" => "true" - response.should be_success - response.body.should =~ /#{Regexp.escape('data-remote="true"')}/ + expect(response).to be_success + expect(response.body).to match(/#{Regexp.escape('data-remote="true"')}/) end it "renders a non-remote form if remote is false" do get :new, "remote" => "false" - response.should be_success - response.body.should_not =~ /#{Regexp.escape('data-remote="true"')}/ + expect(response).to be_success + expect(response.body).not_to match(/#{Regexp.escape('data-remote="true"')}/) end it "renders a non-remote form if remote is missing" do get :new - response.should be_success - response.body.should_not =~ /#{Regexp.escape('data-remote="true"')}/ + expect(response).to be_success + expect(response.body).not_to match(/#{Regexp.escape('data-remote="true"')}/) end end describe "#show" do it "succeeds" do get :show, 'id' => @alices_aspect_1.id.to_s - response.should be_redirect + expect(response).to be_redirect end it 'redirects on an invalid id' do get :show, 'id' => 4341029835 - response.should be_redirect + expect(response).to be_redirect end end describe "#create" do context "with valid params" do it "creates an aspect" do - alice.aspects.count.should == 2 + expect(alice.aspects.count).to eq(2) post :create, "aspect" => {"name" => "new aspect"} - alice.reload.aspects.count.should == 3 + expect(alice.reload.aspects.count).to eq(3) end it "redirects to the aspect's contact page" do post :create, "aspect" => {"name" => "new aspect"} - response.should redirect_to(contacts_path(:a_id => Aspect.find_by_name("new aspect").id)) + expect(response).to redirect_to(contacts_path(:a_id => Aspect.find_by_name("new aspect").id)) end context "with person_id param" do it "creates a contact if one does not already exist" do - lambda { + expect { post :create, :format => 'js', :aspect => {:name => "new", :person_id => eve.person.id} - }.should change { + }.to change { alice.contacts.count }.by(1) end it "adds a new contact to the new aspect" do post :create, :format => 'js', :aspect => {:name => "new", :person_id => eve.person.id} - alice.aspects.find_by_name("new").contacts.count.should == 1 + expect(alice.aspects.find_by_name("new").contacts.count).to eq(1) end it "adds an existing contact to the new aspect" do post :create, :format => 'js', :aspect => {:name => "new", :person_id => bob.person.id} - alice.aspects.find_by_name("new").contacts.count.should == 1 + expect(alice.aspects.find_by_name("new").contacts.count).to eq(1) end end end context "with invalid params" do it "does not create an aspect" do - alice.aspects.count.should == 2 + expect(alice.aspects.count).to eq(2) post :create, "aspect" => {"name" => ""} - alice.reload.aspects.count.should == 2 + expect(alice.reload.aspects.count).to eq(2) end it "goes back to the page you came from" do post :create, "aspect" => {"name" => ""} - response.should redirect_to(:back) + expect(response).to redirect_to(:back) end end end @@ -102,13 +102,13 @@ describe AspectsController do params = {"name" => "Bruisers"} params[:user_id] = new_user.id put('update', :id => @alices_aspect_1.id, "aspect" => params) - Aspect.find(@alices_aspect_1.id).user_id.should == alice.id + expect(Aspect.find(@alices_aspect_1.id).user_id).to eq(alice.id) end it "should return the name and id of the updated item" do params = {"name" => "Bruisers"} put('update', :id => @alices_aspect_1.id, "aspect" => params) - response.body.should == { :id => @alices_aspect_1.id, :name => "Bruisers" }.to_json + expect(response.body).to eq({ :id => @alices_aspect_1.id, :name => "Bruisers" }.to_json) end end @@ -134,25 +134,25 @@ describe AspectsController do it 'renders' do get :edit, :id => @alices_aspect_1.id - response.should be_success + expect(response).to be_success end it 'assigns the contacts in alphabetical order with people in aspects first' do get :edit, :id => @alices_aspect_2.id - assigns[:contacts].map(&:id).should == [alice.contact_for(eve.person), alice.contact_for(@zed.person), alice.contact_for(bob.person), alice.contact_for(@katz.person)].map(&:id) + expect(assigns[:contacts].map(&:id)).to eq([alice.contact_for(eve.person), alice.contact_for(@zed.person), alice.contact_for(bob.person), alice.contact_for(@katz.person)].map(&:id)) end it 'assigns all the contacts if noone is there' do alices_aspect_3 = alice.aspects.create(:name => "aspect 3") get :edit, :id => alices_aspect_3.id - assigns[:contacts].map(&:id).should == [alice.contact_for(bob.person), alice.contact_for(eve.person), alice.contact_for(@katz.person), alice.contact_for(@zed.person)].map(&:id) + expect(assigns[:contacts].map(&:id)).to eq([alice.contact_for(bob.person), alice.contact_for(eve.person), alice.contact_for(@katz.person), alice.contact_for(@zed.person)].map(&:id)) end it 'eager loads the aspect memberships for all the contacts' do get :edit, :id => @alices_aspect_2.id assigns[:contacts].each do |c| - c.aspect_memberships.loaded?.should be true + expect(c.aspect_memberships.loaded?).to be true end end end @@ -163,7 +163,7 @@ describe AspectsController do @alices_aspect_1.save xhr :get, :toggle_contact_visibility, :format => 'js', :aspect_id => @alices_aspect_1.id - @alices_aspect_1.reload.contacts_visible.should be true + expect(@alices_aspect_1.reload.contacts_visible).to be true end it 'sets contacts hidden' do @@ -171,7 +171,7 @@ describe AspectsController do @alices_aspect_1.save xhr :get, :toggle_contact_visibility, :format => 'js', :aspect_id => @alices_aspect_1.id - @alices_aspect_1.reload.contacts_visible.should be false + expect(@alices_aspect_1.reload.contacts_visible).to be false end end end diff --git a/spec/controllers/blocks_controller_spec.rb b/spec/controllers/blocks_controller_spec.rb index de1f81663af669697483ace380aeadfd0191f54b..fe733cf8d41787d16f1f98908e5bdc5b6e2a267a 100644 --- a/spec/controllers/blocks_controller_spec.rb +++ b/spec/controllers/blocks_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe BlocksController do +describe BlocksController, :type => :controller do before do sign_in alice end @@ -15,17 +15,17 @@ describe BlocksController do it "redirects back" do post :create, :block => { :person_id => 2 } - response.should be_redirect + expect(response).to be_redirect end it "notifies the user" do post :create, :block => { :person_id => 2 } - flash.should_not be_empty + expect(flash).not_to be_empty end it "calls #disconnect_if_contact" do - @controller.should_receive(:disconnect_if_contact).with(bob.person) + expect(@controller).to receive(:disconnect_if_contact).with(bob.person) post :create, :block => {:person_id => bob.person.id} end end @@ -37,7 +37,7 @@ describe BlocksController do it "redirects back" do delete :destroy, :id => @block.id - response.should be_redirect + expect(response).to be_redirect end it "removes a block" do @@ -49,18 +49,18 @@ describe BlocksController do describe "#disconnect_if_contact" do before do - @controller.stub(:current_user).and_return(alice) + allow(@controller).to receive(:current_user).and_return(alice) end it "calls disconnect with the force option if there is a contact for a given user" do contact = alice.contact_for(bob.person) - alice.stub(:contact_for).and_return(contact) - alice.should_receive(:disconnect).with(contact, hash_including(:force => true)) + allow(alice).to receive(:contact_for).and_return(contact) + expect(alice).to receive(:disconnect).with(contact, hash_including(:force => true)) @controller.send(:disconnect_if_contact, bob.person) end it "doesn't call disconnect if there is a contact for a given user" do - alice.should_not_receive(:disconnect) + expect(alice).not_to receive(:disconnect) @controller.send(:disconnect_if_contact, eve.person) end end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 8c8f3142e1186be8c119626cf6f42523a8dc14d5..f3e2bf1859fdc956bade40c8e10ee1e7e2c1637a 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -4,9 +4,9 @@ require 'spec_helper' -describe CommentsController do +describe CommentsController, :type => :controller do before do - @controller.stub(:current_user).and_return(alice) + allow(@controller).to receive(:current_user).and_return(alice) sign_in :user, alice end @@ -24,13 +24,13 @@ describe CommentsController do it 'responds to format json' do post :create, comment_hash.merge(:format => 'json') - response.code.should == '201' - response.body.should match comment_hash[:text] + expect(response.code).to eq('201') + expect(response.body).to match comment_hash[:text] end it 'responds to format mobile' do post :create, comment_hash.merge(:format => 'mobile') - response.should be_success + expect(response).to be_success end end @@ -42,21 +42,21 @@ describe CommentsController do it 'comments' do post :create, comment_hash - response.code.should == '201' + expect(response.code).to eq('201') end it "doesn't overwrite author_id" do new_user = FactoryGirl.create(:user) comment_hash[:author_id] = new_user.person.id.to_s post :create, comment_hash - Comment.find_by_text(comment_hash[:text]).author_id.should == alice.person.id + expect(Comment.find_by_text(comment_hash[:text]).author_id).to eq(alice.person.id) end it "doesn't overwrite id" do old_comment = alice.comment!(@post, "hello") comment_hash[:id] = old_comment.id post :create, comment_hash - old_comment.reload.text.should == 'hello' + expect(old_comment.reload.text).to eq('hello') end end @@ -64,9 +64,9 @@ describe CommentsController do aspect_to_post = eve.aspects.where(:name => "generic").first @post = eve.post :status_message, :text => 'GIANTS', :to => aspect_to_post - alice.should_not_receive(:comment) + expect(alice).not_to receive(:comment) post :create, comment_hash - response.code.should == '422' + expect(response.code).to eq('422') end end @@ -78,24 +78,24 @@ describe CommentsController do context 'your post' do before do - @controller.stub(:current_user).and_return(bob) + allow(@controller).to receive(:current_user).and_return(bob) sign_in :user, bob end it 'lets the user delete his comment' do comment = bob.comment!(@message, "hey") - bob.should_receive(:retract).with(comment) + expect(bob).to receive(:retract).with(comment) delete :destroy, :format => "js", :post_id => 1, :id => comment.id - response.status.should == 204 + expect(response.status).to eq(204) end it "lets the user destroy other people's comments" do comment = alice.comment!(@message, "hey") - bob.should_receive(:retract).with(comment) + expect(bob).to receive(:retract).with(comment) delete :destroy, :format => "js", :post_id => 1, :id => comment.id - response.status.should == 204 + expect(response.status).to eq(204) end end @@ -103,25 +103,25 @@ describe CommentsController do it 'let the user delete his comment' do comment = alice.comment!(@message, "hey") - alice.should_receive(:retract).with(comment) + expect(alice).to receive(:retract).with(comment) delete :destroy, :format => "js", :post_id => 1, :id => comment.id - response.status.should == 204 + expect(response.status).to eq(204) end it 'does not let the user destroy comments he does not own' do comment1 = bob.comment!(@message, "hey") comment2 = eve.comment!(@message, "hey") - alice.should_not_receive(:retract).with(comment1) + expect(alice).not_to receive(:retract).with(comment1) delete :destroy, :format => "js", :post_id => 1, :id => comment2.id - response.status.should == 403 + expect(response.status).to eq(403) end end it 'renders nothing and 404 on a nonexistent comment' do delete :destroy, :post_id => 1, :id => 343415 - response.status.should == 404 - response.body.strip.should be_empty + expect(response.status).to eq(404) + expect(response.body.strip).to be_empty end end @@ -133,19 +133,19 @@ describe CommentsController do it 'works for mobile' do get :index, :post_id => @message.id, :format => 'mobile' - response.should be_success + expect(response).to be_success end it 'returns all the comments for a post' do comments = [alice, bob, eve].map{ |u| u.comment!(@message, "hey") } get :index, :post_id => @message.id, :format => :json - assigns[:comments].map(&:id).should =~ comments.map(&:id) + expect(assigns[:comments].map(&:id)).to match_array(comments.map(&:id)) end it 'returns a 404 on a nonexistent post' do get :index, :post_id => 235236, :format => :json - response.status.should == 404 + expect(response.status).to eq(404) end it 'returns a 404 on a post that is not visible to the signed in user' do @@ -153,7 +153,7 @@ describe CommentsController do message = eve.post(:status_message, :text => "hey", :to => aspect_to_post.id) bob.comment!(@message, "hey") get :index, :post_id => message.id, :format => :json - response.status.should == 404 + expect(response.status).to eq(404) end end end diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index ce4f7734c94a83fc2debd00be80b5e47e6f3b46c..a23f9e9ea109c5ad1d5647c27a9108ad58f83f2c 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -4,26 +4,26 @@ require 'spec_helper' -describe ContactsController do +describe ContactsController, :type => :controller do before do sign_in :user, bob - @controller.stub(:current_user).and_return(bob) + allow(@controller).to receive(:current_user).and_return(bob) end describe '#sharing' do it "succeeds" do get :sharing - response.should be_success + expect(response).to be_success end it 'eager loads the aspects' do get :sharing - assigns[:contacts].first.aspect_memberships.loaded?.should be true + expect(assigns[:contacts].first.aspect_memberships.loaded?).to be true end it "assigns only the people sharing with you with 'share_with' flag" do get :sharing, :id => 'share_with' - assigns[:contacts].to_set.should == bob.contacts.sharing.to_set + expect(assigns[:contacts].to_set).to eq(bob.contacts.sharing.to_set) end end @@ -31,20 +31,20 @@ describe ContactsController do context 'format mobile' do it "succeeds" do get :index, :format => 'mobile' - response.should be_success + expect(response).to be_success end end context 'format html' do it "succeeds" do get :index - response.should be_success + expect(response).to be_success end it "assigns contacts" do get :index contacts = assigns(:contacts) - contacts.to_set.should == bob.contacts.to_set + expect(contacts.to_set).to eq(bob.contacts.to_set) end it "shows only contacts a user is sharing with" do @@ -53,7 +53,7 @@ describe ContactsController do get :index, :set => "mine" contacts = assigns(:contacts) - contacts.to_set.should == bob.contacts.receiving.to_set + expect(contacts.to_set).to eq(bob.contacts.receiving.to_set) end it "shows all contacts (sharing and receiving)" do @@ -62,29 +62,29 @@ describe ContactsController do get :index, :set => "all" contacts = assigns(:contacts) - contacts.to_set.should == bob.contacts.to_set + expect(contacts.to_set).to eq(bob.contacts.to_set) end end context 'format json' do it 'assumes all aspects if none are specified' do get :index, :format => 'json' - assigns[:people].map(&:id).should =~ bob.contacts.map { |c| c.person.id } - response.should be_success + expect(assigns[:people].map(&:id)).to match_array(bob.contacts.map { |c| c.person.id }) + expect(response).to be_success end it 'returns the contacts for multiple aspects' do get :index, :aspect_ids => bob.aspect_ids, :format => 'json' - assigns[:people].map(&:id).should =~ bob.contacts.map { |c| c.person.id } - response.should be_success + expect(assigns[:people].map(&:id)).to match_array(bob.contacts.map { |c| c.person.id }) + expect(response).to be_success end it 'does not return duplicate contacts' do aspect = bob.aspects.create(:name => 'hilarious people') aspect.contacts << bob.contact_for(eve.person) get :index, :format => 'json', :aspect_ids => bob.aspect_ids - assigns[:people].map { |p| p.id }.uniq.should == assigns[:people].map { |p| p.id } - assigns[:people].map(&:id).should =~ bob.contacts.map { |c| c.person.id } + expect(assigns[:people].map { |p| p.id }.uniq).to eq(assigns[:people].map { |p| p.id }) + expect(assigns[:people].map(&:id)).to match_array(bob.contacts.map { |c| c.person.id }) end end end @@ -92,14 +92,14 @@ describe ContactsController do describe '#spotlight' do it 'succeeds' do get :spotlight - response.should be_success + expect(response).to be_success end it 'gets queries for users in the app config' do Role.add_spotlight(alice.person) get :spotlight - assigns[:people].should == [alice.person] + expect(assigns[:people]).to eq([alice.person]) end end end diff --git a/spec/controllers/conversation_visibilities_controller_spec.rb b/spec/controllers/conversation_visibilities_controller_spec.rb index 54993fd72b77c52f211c1ec2a2596c237f77f8fc..4af785a315f6f81cadb3d4486fcb65d548d11e22 100644 --- a/spec/controllers/conversation_visibilities_controller_spec.rb +++ b/spec/controllers/conversation_visibilities_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ConversationVisibilitiesController do +describe ConversationVisibilitiesController, :type => :controller do before do @user1 = alice sign_in :user, @user1 @@ -20,18 +20,18 @@ describe ConversationVisibilitiesController do describe '#destroy' do it 'deletes the visibility' do - lambda { + expect { delete :destroy, :conversation_id => @conversation.id - }.should change(ConversationVisibility, :count).by(-1) + }.to change(ConversationVisibility, :count).by(-1) end it 'does not let a user destroy a visibility that is not theirs' do user2 = eve sign_in :user, user2 - lambda { + expect { delete :destroy, :conversation_id => @conversation.id - }.should_not change(ConversationVisibility, :count) + }.not_to change(ConversationVisibility, :count) end end end \ No newline at end of file diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 9c293f10776e1a33ffa67f48cdf8a771a7cc9d67..bfc5ebf732a6a53dfa80bb57520b66bda446804a 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ConversationsController do +describe ConversationsController, :type => :controller do before do sign_in :user, alice end @@ -15,30 +15,30 @@ describe ConversationsController do end it 'succeeds' do - response.should be_success + expect(response).to be_success end it "assigns a json list of contacts that are sharing with the person" do - assigns(:contacts_json).should include(alice.contacts.where(:sharing => true).first.person.name) + expect(assigns(:contacts_json)).to include(alice.contacts.where(:sharing => true).first.person.name) alice.contacts << Contact.new(:person_id => eve.person.id, :user_id => alice.id, :sharing => false, :receiving => true) - assigns(:contacts_json).should_not include(alice.contacts.where(:sharing => false).first.person.name) + expect(assigns(:contacts_json)).not_to include(alice.contacts.where(:sharing => false).first.person.name) end it "assigns a contact if passed a contact id" do get :new, :contact_id => alice.contacts.first.id - assigns(:contact_ids).should == alice.contacts.first.id + expect(assigns(:contact_ids)).to eq(alice.contacts.first.id) end it "assigns a set of contacts if passed an aspect id" do get :new, :aspect_id => alice.aspects.first.id - assigns(:contact_ids).should == alice.aspects.first.contacts.map(&:id).join(',') + expect(assigns(:contact_ids)).to eq(alice.aspects.first.contacts.map(&:id).join(',')) end it "does not allow XSS via the name parameter" do ["</script><script>alert(1);</script>", '"}]});alert(1);(function f() {var foo = [{b:"'].each do |xss| get :new, name: xss - response.body.should_not include xss + expect(response.body).not_to include xss end end end @@ -56,20 +56,20 @@ describe ConversationsController do it 'succeeds' do get :index - response.should be_success - assigns[:conversations].should =~ @conversations + expect(response).to be_success + expect(assigns[:conversations]).to match_array(@conversations) end it 'succeeds with json' do get :index, :format => :json - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json.first['conversation'].should be_present + expect(json.first['conversation']).to be_present end it 'retrieves all conversations for a user' do get :index - assigns[:conversations].count.should == 3 + expect(assigns[:conversations].count).to eq(3) end end @@ -87,29 +87,29 @@ describe ConversationsController do end it 'creates a conversation' do - lambda { + expect { post :create, @hash - }.should change(Conversation, :count).by(1) + }.to change(Conversation, :count).by(1) end it 'creates a message' do - lambda { + expect { post :create, @hash - }.should change(Message, :count).by(1) + }.to change(Message, :count).by(1) end it 'should set response with success to true and message to success message' do post :create, @hash - assigns[:response][:success].should == true - assigns[:response][:message].should == I18n.t('conversations.create.sent') - assigns[:response][:conversation_id].should == Conversation.first.id + expect(assigns[:response][:success]).to eq(true) + expect(assigns[:response][:message]).to eq(I18n.t('conversations.create.sent')) + expect(assigns[:response][:conversation_id]).to eq(Conversation.first.id) end it 'sets the author to the current_user' do @hash[:author] = FactoryGirl.create(:user) post :create, @hash - Message.first.author.should == alice.person - Conversation.first.author.should == alice.person + expect(Message.first.author).to eq(alice.person) + expect(Conversation.first.author).to eq(alice.person) end it 'dispatches the conversation' do @@ -123,8 +123,8 @@ describe ConversationsController do ) p = Postzord::Dispatcher.build(alice, cnv) - p.class.stub(:new).and_return(p) - p.should_receive(:post) + allow(p.class).to receive(:new).and_return(p) + expect(p).to receive(:post) post :create, @hash end end @@ -142,22 +142,22 @@ describe ConversationsController do end it 'creates a conversation' do - lambda { + expect { post :create, @hash - }.should change(Conversation, :count).by(1) + }.to change(Conversation, :count).by(1) end it 'creates a message' do - lambda { + expect { post :create, @hash - }.should change(Message, :count).by(1) + }.to change(Message, :count).by(1) end it 'should set response with success to true and message to success message' do post :create, @hash - assigns[:response][:success].should == true - assigns[:response][:message].should == I18n.t('conversations.create.sent') - assigns[:response][:conversation_id].should == Conversation.first.id + expect(assigns[:response][:success]).to eq(true) + expect(assigns[:response][:message]).to eq(I18n.t('conversations.create.sent')) + expect(assigns[:response][:conversation_id]).to eq(Conversation.first.id) end end @@ -176,19 +176,19 @@ describe ConversationsController do it 'does not create a conversation' do count = Conversation.count post :create, @hash - Conversation.count.should == count + expect(Conversation.count).to eq(count) end it 'does not create a message' do count = Message.count post :create, @hash - Message.count.should == count + expect(Message.count).to eq(count) end it 'should set response with success to false and message to create fail' do post :create, @hash - assigns[:response][:success].should == false - assigns[:response][:message].should == I18n.t('conversations.create.fail') + expect(assigns[:response][:success]).to eq(false) + expect(assigns[:response][:message]).to eq(I18n.t('conversations.create.fail')) end end @@ -207,19 +207,19 @@ describe ConversationsController do it 'does not create a conversation' do count = Conversation.count post :create, @hash - Conversation.count.should == count + expect(Conversation.count).to eq(count) end it 'does not create a message' do count = Message.count post :create, @hash - Message.count.should == count + expect(Message.count).to eq(count) end it 'should set response with success to false and message to fail due to no contact' do post :create, @hash - assigns[:response][:success].should == false - assigns[:response][:message].should == I18n.t('conversations.create.no_contact') + expect(assigns[:response][:success]).to eq(false) + expect(assigns[:response][:message]).to eq(I18n.t('conversations.create.no_contact')) end end @@ -238,13 +238,13 @@ describe ConversationsController do it 'does not create a conversation' do count = Conversation.count post :create, @hash - Conversation.count.should == count + expect(Conversation.count).to eq(count) end it 'does not create a message' do count = Message.count post :create, @hash - Message.count.should == count + expect(Message.count).to eq(count) end end end @@ -262,28 +262,28 @@ describe ConversationsController do it 'succeeds with js' do xhr :get, :show, :id => @conversation.id, :format => :js - response.should be_success - assigns[:conversation].should == @conversation + expect(response).to be_success + expect(assigns[:conversation]).to eq(@conversation) end it 'succeeds with json' do get :show, :id => @conversation.id, :format => :json - response.should be_success - assigns[:conversation].should == @conversation - response.body.should include @conversation.guid + expect(response).to be_success + expect(assigns[:conversation]).to eq(@conversation) + expect(response.body).to include @conversation.guid end it 'redirects to index' do get :show, :id => @conversation.id - response.should redirect_to(conversations_path(:conversation_id => @conversation.id)) - assigns[:conversation].should == @conversation + expect(response).to redirect_to(conversations_path(:conversation_id => @conversation.id)) + expect(assigns[:conversation]).to eq(@conversation) end it 'does not let you access conversations where you are not a recipient' do sign_in :user, eve get :show, :id => @conversation.id - response.code.should redirect_to conversations_path + expect(response.code).to redirect_to conversations_path end end end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index cd9a6958cc563282c97dea0a988968e8dae7bec2..f34d3671ee442e63a95ea113e9dd2c58023de40d 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper' -describe HomeController do +describe HomeController, :type => :controller do describe '#show' do it 'does not redirect' do sign_out :user get :show - response.should_not be_redirect + expect(response).not_to be_redirect end context 'redirection' do @@ -19,7 +19,7 @@ describe HomeController do it 'points to the stream if a user has contacts' do get :show, :home => true - response.should redirect_to(stream_path) + expect(response).to redirect_to(stream_path) end end end @@ -28,13 +28,13 @@ describe HomeController do it 'changes :mobile to :html' do session[:mobile_view] = true get :toggle_mobile - session[:mobile_view].should be false + expect(session[:mobile_view]).to be false end it 'changes :html to :mobile' do session[:mobile_view] = nil get :toggle_mobile - session[:mobile_view].should be true + expect(session[:mobile_view]).to be true end end end diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 852181ada57d46486ce4403916613d1a29419a3b..ee1d0500927ce7e9cc70cd67fb4413f65b5b7605 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe InvitationsController do +describe InvitationsController, :type => :controller do before do AppConfig.settings.invitations.open = true @@ -15,7 +15,7 @@ describe InvitationsController do describe "#create" do before do sign_in :user, @user - @controller.stub(:current_user).and_return(@user) + allow(@controller).to receive(:current_user).and_return(@user) @referer = 'http://test.host/cats/foo' request.env["HTTP_REFERER"] = @referer end @@ -26,18 +26,18 @@ describe InvitationsController do end it 'does not create an EmailInviter' do - Workers::Mail::InviteEmail.should_not_receive(:perform_async) + expect(Workers::Mail::InviteEmail).not_to receive(:perform_async) post :create, @invite end it 'returns to the previous page' do post :create, @invite - response.should redirect_to @referer + expect(response).to redirect_to @referer end it 'flashes an error' do post :create, @invite - flash[:error].should == I18n.t("invitations.create.empty") + expect(flash[:error]).to eq(I18n.t("invitations.create.empty")) end end @@ -49,19 +49,19 @@ describe InvitationsController do it 'creates an InviteEmail worker' do inviter = double(:emails => [@emails], :send! => true) - Workers::Mail::InviteEmail.should_receive(:perform_async).with(@invite['email_inviter']['emails'], @user.id, @invite['email_inviter']) + expect(Workers::Mail::InviteEmail).to receive(:perform_async).with(@invite['email_inviter']['emails'], @user.id, @invite['email_inviter']) post :create, @invite end it 'returns to the previous page on success' do post :create, @invite - response.should redirect_to @referer + expect(response).to redirect_to @referer end it 'flashes a notice' do post :create, @invite expected = I18n.t('invitations.create.sent', :emails => @emails.split(',').join(', ')) - flash[:notice].should == expected + expect(flash[:notice]).to eq(expected) end end @@ -72,20 +72,20 @@ describe InvitationsController do end it 'does not create an InviteEmail worker' do - Workers::Mail::InviteEmail.should_not_receive(:perform_async) + expect(Workers::Mail::InviteEmail).not_to receive(:perform_async) post :create, @invite end it 'returns to the previous page' do post :create, @invite - response.should redirect_to @referer + expect(response).to redirect_to @referer end it 'flashes an error' do post :create, @invite expected = I18n.t('invitations.create.rejected') + @emails.split(',').join(', ') - flash[:error].should == expected + expect(flash[:error]).to eq(expected) end end @@ -99,13 +99,13 @@ describe InvitationsController do it 'creates an InviteEmail worker' do inviter = double(:emails => [@emails], :send! => true) - Workers::Mail::InviteEmail.should_receive(:perform_async).with(@valid_emails, @user.id, @invite['email_inviter']) + expect(Workers::Mail::InviteEmail).to receive(:perform_async).with(@valid_emails, @user.id, @invite['email_inviter']) post :create, @invite end it 'returns to the previous page' do post :create, @invite - response.should redirect_to @referer + expect(response).to redirect_to @referer end it 'flashes a notice' do @@ -114,7 +114,7 @@ describe InvitationsController do @valid_emails.split(',').join(', ')) + '. ' + I18n.t('invitations.create.rejected') + @invalid_emails.split(',').join(', ') - flash[:error].should == expected + expect(flash[:error]).to eq(expected) end end @@ -123,7 +123,7 @@ describe InvitationsController do AppConfig.settings.invitations.open = false post :create, @invite - response.should be_redirect + expect(response).to be_redirect AppConfig.settings.invitations.open = open_bit end end @@ -132,7 +132,7 @@ describe InvitationsController do it 'succeeds' do get :email, :invitation_code => "anycode" - response.should be_success + expect(response).to be_success end context 'legacy invite tokens' do @@ -146,14 +146,14 @@ describe InvitationsController do it 'redirects and flashes if the invitation token is invalid' do get_email - response.should be_redirect - response.should redirect_to root_url + expect(response).to be_redirect + expect(response).to redirect_to root_url end it 'flashes an error if the invitation token is invalid' do get_email - flash[:error].should == I18n.t("invitations.check_token.not_found") + expect(flash[:error]).to eq(I18n.t("invitations.check_token.not_found")) end end end @@ -169,50 +169,50 @@ describe InvitationsController do describe 'redirect logged out users to the sign in page' do it 'redriects #new' do get :new - response.should be_redirect - response.should redirect_to new_user_session_path + expect(response).to be_redirect + expect(response).to redirect_to new_user_session_path end it 'redirects #create' do post :create - response.should be_redirect - response.should redirect_to new_user_session_path + expect(response).to be_redirect + expect(response).to redirect_to new_user_session_path end end describe '.valid_email?' do it 'returns false for empty email' do - subject.send(:valid_email?, '').should be false + expect(subject.send(:valid_email?, '')).to be false end it 'returns false for email without @-sign' do - subject.send(:valid_email?, 'foo').should be false + expect(subject.send(:valid_email?, 'foo')).to be false end it 'returns true for valid email' do - subject.send(:valid_email?, 'foo@bar.com').should be true + expect(subject.send(:valid_email?, 'foo@bar.com')).to be true end end describe '.html_safe_string_from_session_array' do it 'returns "" for blank session[key]' do - subject.send(:html_safe_string_from_session_array, :blank).should eq "" + expect(subject.send(:html_safe_string_from_session_array, :blank)).to eq "" end it 'returns "" if session[key] is not an array' do session[:test_key] = "test" - subject.send(:html_safe_string_from_session_array, :test_key).should eq "" + expect(subject.send(:html_safe_string_from_session_array, :test_key)).to eq "" end it 'returns the correct value' do session[:test_key] = ["test", "foo"] - subject.send(:html_safe_string_from_session_array, :test_key).should eq "test, foo" + expect(subject.send(:html_safe_string_from_session_array, :test_key)).to eq "test, foo" end it 'sets session[key] to nil' do session[:test_key] = ["test"] subject.send(:html_safe_string_from_session_array, :test_key) - session[:test_key].should be nil + expect(session[:test_key]).to be nil end end end diff --git a/spec/controllers/jasmine_fixtures/aspects_spec.rb b/spec/controllers/jasmine_fixtures/aspects_spec.rb index 7cb66843b9346ae718813b9565e7c4887611edc2..4d2d6810830be4c2a549c00904f5644b25f6b147 100644 --- a/spec/controllers/jasmine_fixtures/aspects_spec.rb +++ b/spec/controllers/jasmine_fixtures/aspects_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe StreamsController do +describe StreamsController, :type => :controller do describe '#aspects' do before do sign_in :user, alice @@ -15,7 +15,7 @@ describe StreamsController do context 'jasmine fixtures' do before do - Stream::Aspect.any_instance.stub(:ajax_stream?).and_return(false) + allow_any_instance_of(Stream::Aspect).to receive(:ajax_stream?).and_return(false) end it "generates a jasmine fixture", :fixture => true do diff --git a/spec/controllers/jasmine_fixtures/contacts_spec.rb b/spec/controllers/jasmine_fixtures/contacts_spec.rb index d2a5321de6c24799a2e3af2e2db0799f2f9c8b37..127092daf42620648cb71718d33ab832e4d7d456 100644 --- a/spec/controllers/jasmine_fixtures/contacts_spec.rb +++ b/spec/controllers/jasmine_fixtures/contacts_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ContactsController do +describe ContactsController, :type => :controller do describe '#index' do before do sign_in :user, bob diff --git a/spec/controllers/jasmine_fixtures/notifications_spec.rb b/spec/controllers/jasmine_fixtures/notifications_spec.rb index 8851eb02ddc935c118fbc80407f107a0a6179caa..771d99ec549f7060e9cfd98c5c84a45efeef6def 100644 --- a/spec/controllers/jasmine_fixtures/notifications_spec.rb +++ b/spec/controllers/jasmine_fixtures/notifications_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe NotificationsController do +describe NotificationsController, :type => :controller do describe '#index' do before do sign_in :user, alice diff --git a/spec/controllers/jasmine_fixtures/people_spec.rb b/spec/controllers/jasmine_fixtures/people_spec.rb index 5e8d3ed047dbdd0bac4763c394a5c09cdd9eea16..814dc66c366bedb5eef5e4a252098defa23c2462 100644 --- a/spec/controllers/jasmine_fixtures/people_spec.rb +++ b/spec/controllers/jasmine_fixtures/people_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PeopleController do +describe PeopleController, :type => :controller do describe '#index' do before do sign_in :user, bob diff --git a/spec/controllers/jasmine_fixtures/status_messages_spec.rb b/spec/controllers/jasmine_fixtures/status_messages_spec.rb index 90a2f9df6dd5d6411787d334e9ed08e2ba04e0d2..56d36d8009971f6f8f2b88915c580553a0226b2e 100644 --- a/spec/controllers/jasmine_fixtures/status_messages_spec.rb +++ b/spec/controllers/jasmine_fixtures/status_messages_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe StatusMessagesController do +describe StatusMessagesController, :type => :controller do describe '#bookmarklet' do before do sign_in :user, bob diff --git a/spec/controllers/jasmine_fixtures/streams_spec.rb b/spec/controllers/jasmine_fixtures/streams_spec.rb index 2a3a8a1b848f70c045e747760b6b079e8e16b4c2..94e0cbb032137c8a686f404737f1f7ea6dddc7da 100644 --- a/spec/controllers/jasmine_fixtures/streams_spec.rb +++ b/spec/controllers/jasmine_fixtures/streams_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe StreamsController do +describe StreamsController, :type => :controller do describe '#multi' do before do sign_in :user, alice @@ -53,7 +53,7 @@ TXT Timecop.travel(time) do get :multi, :format => :json - response.should be_success + expect(response).to be_success save_fixture(response.body, "stream_json") end end diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index dfaddc41377e38d7b33f6f82e8c1741ac1a9a46c..7cc8d3d399008d0ca54241841760cf7a96205182 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe LikesController do +describe LikesController, :type => :controller do before do @alices_aspect = alice.aspects.where(:name => "generic").first @bobs_aspect = bob.aspects.where(:name => "generic").first @@ -33,7 +33,7 @@ describe LikesController do @target = alice.post :status_message, :text => "AWESOME", :to => @alices_aspect.id @target = alice.comment!(@target, "hey") if class_const == Comment post :create, like_hash.merge(:format => :json) - response.code.should == '201' + expect(response.code).to eq('201') end end @@ -45,18 +45,18 @@ describe LikesController do it 'likes' do post :create, like_hash - response.code.should == '201' + expect(response.code).to eq('201') end it 'dislikes' do post :create, dislike_hash - response.code.should == '201' + expect(response.code).to eq('201') end it "doesn't post multiple times" do alice.like!(@target) post :create, dislike_hash - response.code.should == '422' + expect(response.code).to eq('422') end end @@ -67,9 +67,9 @@ describe LikesController do end it "doesn't post" do - alice.should_not_receive(:like!) + expect(alice).not_to receive(:like!) post :create, like_hash - response.code.should == '422' + expect(response.code).to eq('422') end end end @@ -94,12 +94,12 @@ describe LikesController do it 'returns an array of likes for a post' do like = bob.like!(@message) get :index, id_field => @message.id - assigns[:likes].map(&:id).should == @message.likes.map(&:id) + expect(assigns[:likes].map(&:id)).to eq(@message.likes.map(&:id)) end it 'returns an empty array for a post with no likes' do get :index, id_field => @message.id - assigns[:likes].should == [] + expect(assigns[:likes]).to eq([]) end end @@ -112,10 +112,10 @@ describe LikesController do it 'lets a user destroy their like' do current_user = controller.send(:current_user) - current_user.should_receive(:retract).with(@like) + expect(current_user).to receive(:retract).with(@like) delete :destroy, :format => :json, id_field => @like.target_id, :id => @like.id - response.status.should == 204 + expect(response.status).to eq(204) end it 'does not let a user destroy other likes' do @@ -126,7 +126,7 @@ describe LikesController do delete :destroy, :format => :json, id_field => like2.target_id, :id => like2.id }.to raise_error(ActiveRecord::RecordNotFound) - Like.count.should == like_count + expect(Like.count).to eq(like_count) end end diff --git a/spec/controllers/messages_controller_spec.rb b/spec/controllers/messages_controller_spec.rb index 4e3116cf2fd7994310e927433dae7f524b019176..c4364ef9e0c5886a736dd31989e4fd5ab2f00320 100644 --- a/spec/controllers/messages_controller_spec.rb +++ b/spec/controllers/messages_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe MessagesController do +describe MessagesController, :type => :controller do before do sign_in :user, alice end @@ -33,11 +33,11 @@ describe MessagesController do end it 'redirects to conversation' do - lambda { + expect { post :create, @message_params - }.should change(Message, :count).by(1) - response.status.should == 302 - response.should redirect_to(conversations_path(:conversation_id => @conversation)) + }.to change(Message, :count).by(1) + expect(response.status).to eq(302) + expect(response).to redirect_to(conversations_path(:conversation_id => @conversation)) end end @@ -50,10 +50,10 @@ describe MessagesController do end it 'does not create the message' do - lambda { + expect { post :create, @message_params - }.should_not change(Message, :count) - flash[:error].should be_present + }.not_to change(Message, :count) + expect(flash[:error]).to be_present end end end @@ -70,8 +70,8 @@ describe MessagesController do it 'comments' do post :create, @message_params - response.status.should == 302 - response.should redirect_to(conversations_path(:conversation_id => @conversation)) + expect(response.status).to eq(302) + expect(response).to redirect_to(conversations_path(:conversation_id => @conversation)) end it "doesn't overwrite author_id" do @@ -80,7 +80,7 @@ describe MessagesController do post :create, @message_params created_message = Message.find_by_text(@message_params[:message][:text]) - created_message.author.should == alice.person + expect(created_message.author).to eq(alice.person) end it "doesn't overwrite id" do @@ -92,7 +92,7 @@ describe MessagesController do @message_params[:id] = old_message.id post :create, @message_params - old_message.reload.text.should == 'hello' + expect(old_message.reload.text).to eq('hello') end end @@ -109,10 +109,10 @@ describe MessagesController do end it 'does not create the message' do - lambda { + expect { post :create, @message_params - }.should_not change(Message, :count) - flash[:error].should be_present + }.not_to change(Message, :count) + expect(flash[:error]).to be_present end end end diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 502d63363146fe33f52f14dfbbd006634460bfa0..b27b36da463e4b61ea1f6604e31628899e46444a 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe NotificationsController do +describe NotificationsController, :type => :controller do before do sign_in :user, alice end @@ -12,22 +12,22 @@ describe NotificationsController do describe '#update' do it 'marks a notification as read if it gets no other information' do note = FactoryGirl.create(:notification) - Notification.should_receive( :where ).and_return( [note] ) - note.should_receive( :set_read_state ).with( true ) + expect(Notification).to receive( :where ).and_return( [note] ) + expect(note).to receive( :set_read_state ).with( true ) get :update, "id" => note.id, :format => :json end it 'marks a notification as read if it is told to' do note = FactoryGirl.create(:notification) - Notification.should_receive( :where ).and_return( [note] ) - note.should_receive( :set_read_state ).with( true ) + expect(Notification).to receive( :where ).and_return( [note] ) + expect(note).to receive( :set_read_state ).with( true ) get :update, "id" => note.id, :set_unread => "false", :format => :json end it 'marks a notification as unread if it is told to' do note = FactoryGirl.create(:notification) - Notification.should_receive( :where ).and_return( [note] ) - note.should_receive( :set_read_state ).with( false ) + expect(Notification).to receive( :where ).and_return( [note] ) + expect(note).to receive( :set_read_state ).with( false ) get :update, "id" => note.id, :set_unread => "true", :format => :json end @@ -39,7 +39,7 @@ describe NotificationsController do get :update, "id" => note.id, :set_unread => "false", :format => :json - Notification.find(note.id).unread.should == true + expect(Notification.find(note.id).unread).to eq(true) end end @@ -51,33 +51,33 @@ describe NotificationsController do it 'succeeds' do get :index - response.should be_success - assigns[:notifications].count.should == 1 + expect(response).to be_success + expect(assigns[:notifications].count).to eq(1) end it 'succeeds for notification dropdown' do get :index, :format => :json - response.should be_success - response.body.should =~ /note_html/ + expect(response).to be_success + expect(response.body).to match(/note_html/) end it 'succeeds on mobile' do get :index, :format => :mobile - response.should be_success + expect(response).to be_success end it 'paginates the notifications' do 25.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } get :index - assigns[:notifications].count.should == 25 + expect(assigns[:notifications].count).to eq(25) get :index, "page" => 2 - assigns[:notifications].count.should == 1 + expect(assigns[:notifications].count).to eq(1) end it "supports a limit per_page parameter" do 5.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } get :index, "per_page" => 5 - assigns[:notifications].count.should == 5 + expect(assigns[:notifications].count).to eq(5) end describe "special case for start sharing notifications" do @@ -85,14 +85,14 @@ describe NotificationsController do 2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } get :index, "per_page" => 5 - Nokogiri(response.body).css('.aspect_membership').should be_empty + expect(Nokogiri(response.body).css('.aspect_membership')).to be_empty end it "should provide a contacts menu for start sharing notifications" do 2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } eve.share_with(alice.person, eve.aspects.first) get :index, "per_page" => 5 - Nokogiri(response.body).css('.aspect_membership').should_not be_empty + expect(Nokogiri(response.body).css('.aspect_membership')).not_to be_empty end end @@ -100,14 +100,14 @@ describe NotificationsController do it "supports filtering by notification type" do eve.share_with(alice.person, eve.aspects.first) get :index, "type" => "started_sharing" - assigns[:notifications].count.should == 1 + expect(assigns[:notifications].count).to eq(1) end it "supports filtering by read/unread" do get :read_all 2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } get :index, "show" => "unread" - assigns[:notifications].count.should == 2 + expect(assigns[:notifications].count).to eq(2) end end end @@ -118,44 +118,44 @@ describe NotificationsController do FactoryGirl.create(:notification, :recipient => alice) FactoryGirl.create(:notification, :recipient => alice) - Notification.where(:unread => true).count.should == 2 + expect(Notification.where(:unread => true).count).to eq(2) get :read_all - Notification.where(:unread => true).count.should == 0 + expect(Notification.where(:unread => true).count).to eq(0) end it 'marks all notifications in the current filter as read' do request.env["HTTP_REFERER"] = "I wish I were spelled right" FactoryGirl.create(:notification, :recipient => alice) eve.share_with(alice.person, eve.aspects.first) - Notification.where(:unread => true).count.should == 2 + expect(Notification.where(:unread => true).count).to eq(2) get :read_all, "type" => "started_sharing" - Notification.where(:unread => true).count.should == 1 + expect(Notification.where(:unread => true).count).to eq(1) end it "should redirect back in the html version if it has > 0 notifications" do FactoryGirl.create(:notification, :recipient => alice) eve.share_with(alice.person, eve.aspects.first) get :read_all, :format => :html, "type" => "started_sharing" - response.should redirect_to(notifications_path) + expect(response).to redirect_to(notifications_path) end it "should redirect back in the mobile version if it has > 0 notifications" do FactoryGirl.create(:notification, :recipient => alice) eve.share_with(alice.person, eve.aspects.first) get :read_all, :format => :mobile, "type" => "started_sharing" - response.should redirect_to(notifications_path) + expect(response).to redirect_to(notifications_path) end it "should redirect to stream in the html version if it has 0 notifications" do FactoryGirl.create(:notification, :recipient => alice) get :read_all, :format => :html - response.should redirect_to(stream_path) + expect(response).to redirect_to(stream_path) end it "should redirect back in the mobile version if it has 0 notifications" do FactoryGirl.create(:notification, :recipient => alice) get :read_all, :format => :mobile - response.should redirect_to(stream_path) + expect(response).to redirect_to(stream_path) end it "should return a dummy value in the json version" do FactoryGirl.create(:notification, :recipient => alice) get :read_all, :format => :json - response.should_not be_redirect + expect(response).not_to be_redirect end end end diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index b5d2880e899b24a4baa7ec24ca87a71094fa0754..3d00b17b8bc6a20c6adf0454938292bac7e7e3d7 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/spec/controllers/passwords_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PasswordsController do +describe PasswordsController, :type => :controller do include Devise::TestHelpers before do @@ -15,21 +15,21 @@ describe PasswordsController do context "when there is no such user" do it "succeeds" do post :create, "user" => {"email" => "foo@example.com"} - response.should be_success + expect(response).to be_success end it "doesn't send email" do - Workers::ResetPassword.should_not_receive(:perform_async) + expect(Workers::ResetPassword).not_to receive(:perform_async) post :create, "user" => {"email" => "foo@example.com"} end end context "when there is a user with that email" do it "redirects to the login page" do post :create, "user" => {"email" => alice.email} - response.should redirect_to(new_user_session_path) + expect(response).to redirect_to(new_user_session_path) end it "sends email (enqueued to Sidekiq)" do - Workers::ResetPassword.should_receive(:perform_async).with(alice.id) + expect(Workers::ResetPassword).to receive(:perform_async).with(alice.id) post :create, "user" => {"email" => alice.email} end end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index d1faab62299783319fd4e13f9ee723cd2983c1c4..a89755a4854a5b46d7d57e8f7026a21c8958fae2 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PeopleController do +describe PeopleController, :type => :controller do before do @user = alice @aspect = @user.aspects.first @@ -22,17 +22,17 @@ describe PeopleController do describe 'via json' do it 'succeeds' do get :index, :q => "Korth", :format => 'json' - response.should be_success + expect(response).to be_success end it 'responds with json' do get :index, :q => "Korth", :format => 'json' - response.body.should == [@korth].to_json + expect(response.body).to eq([@korth].to_json) end it 'does not assign hashes' do get :index, :q => "Korth", :format => 'json' - assigns[:hashes].should be_nil + expect(assigns[:hashes]).to be_nil end end @@ -45,34 +45,34 @@ describe PeopleController do end it 'finds people even if they have searchable off' do get :index, :q => "eugene@example.org" - assigns[:people][0].id.should == @unsearchable_eugene.id + expect(assigns[:people][0].id).to eq(@unsearchable_eugene.id) end it 'downcases the query term' do get :index, :q => "Eugene@Example.ORG" - assigns[:people][0].id.should == @unsearchable_eugene.id + expect(assigns[:people][0].id).to eq(@unsearchable_eugene.id) end it 'does not the background query task if the user is found' do get :index, :q => "Eugene@Example.ORG" - assigns[:background_query].should == nil + expect(assigns[:background_query]).to eq(nil) end it 'sets background query task if the user is not found' do get :index, :q => "Eugene@Example1.ORG" - assigns[:background_query].should == "eugene@example1.org" + expect(assigns[:background_query]).to eq("eugene@example1.org") end end context 'query is not a tag or a diaspora ID' do it 'assigns hashes' do get :index, :q => "Korth" - assigns[:hashes].should_not be_nil + expect(assigns[:hashes]).not_to be_nil end it 'does not set the background query task' do get :index, :q => "Korth" - assigns[:background_query].should_not be_present + expect(assigns[:background_query]).not_to be_present end it "assigns people" do @@ -80,29 +80,29 @@ describe PeopleController do :profile => FactoryGirl.build(:profile, :first_name => "Eugene", :last_name => "w")) get :index, :q => "Eug" - assigns[:people].map { |x| x.id }.should =~ [@eugene.id, eugene2.id] + expect(assigns[:people].map { |x| x.id }).to match_array([@eugene.id, eugene2.id]) end it "succeeds if there is exactly one match" do get :index, :q => "Korth" - assigns[:people].length.should == 1 - response.should be_success + expect(assigns[:people].length).to eq(1) + expect(response).to be_success end it "succeeds if there are no matches" do get :index, :q => "Korthsauce" - assigns[:people].length.should == 0 - response.should be_success + expect(assigns[:people].length).to eq(0) + expect(response).to be_success end it 'succeeds if you search for the empty term' do get :index, :q => '' - response.should be_success + expect(response).to be_success end it 'succeeds if you search for punctuation' do get :index, :q => '+' - response.should be_success + expect(response).to be_success end it "excludes people who have searchable off" do @@ -110,7 +110,7 @@ describe PeopleController do :profile => FactoryGirl.build(:profile, :first_name => "Eugene", :last_name => "w", :searchable => false)) get :index, :q => "Eug" - assigns[:people].should_not =~ [eugene2] + expect(assigns[:people]).not_to match_array([eugene2]) end end end @@ -119,7 +119,7 @@ describe PeopleController do describe '#tag_index' do it 'works for js' do xhr :get, :tag_index, :name => 'jellybeans', :format => :js - response.should be_success + expect(response).to be_success end it 'returns awesome people who have that tag' do @@ -127,7 +127,7 @@ describe PeopleController do f.profile.tag_string = "#seeded" f.profile.save xhr :get, :tag_index, :name => 'seeded', :format => :js - assigns[:people].count.should == 1 + expect(assigns[:people].count).to eq(1) end end @@ -152,33 +152,33 @@ describe PeopleController do end it 'takes time' do - Benchmark.realtime { + expect(Benchmark.realtime { get :show, :id => @user.person.to_param - }.should < 1.0 + }).to be < 1.0 end end describe '#show' do it "404s if the id is invalid" do get :show, :id => 'delicious' - response.code.should == "404" + expect(response.code).to eq("404") end it "404s if no person is found via id" do get :show, :id => "3d920397846" - response.code.should == "404" + expect(response.code).to eq("404") end it "404s if no person is found via username" do get :show, :username => 'delicious' - response.code.should == "404" + expect(response.code).to eq("404") end it 'redirects home for closed account' do @person = FactoryGirl.create(:person, :closed_account => true) get :show, :id => @person.to_param - response.should be_redirect - flash[:notice].should_not be_blank + expect(response).to be_redirect + expect(flash[:notice]).not_to be_blank end it 'does not allow xss attacks' do @@ -186,8 +186,8 @@ describe PeopleController do profile = user2.profile profile.update_attribute(:first_name, "</script><script> alert('xss attack');</script>") get :show, :id => user2.person.to_param - response.should be_success - response.body.should_not include(profile.first_name) + expect(response).to be_success + expect(response.body).not_to include(profile.first_name) end it "doesn't leak photos in the sidebar" do @@ -197,41 +197,41 @@ describe PeopleController do sign_out :user get :show, id: @user.person.to_param - assigns(:photos).should_not include private_photo - assigns(:photos).should include public_photo + expect(assigns(:photos)).not_to include private_photo + expect(assigns(:photos)).to include public_photo end context "when the person is the current user" do it "succeeds" do get :show, :id => @user.person.to_param - response.should be_success + expect(response).to be_success end it 'succeeds on the mobile site' do get :show, :id => @user.person.to_param, :format => :mobile - response.should be_success + expect(response).to be_success end it "assigns the right person" do get :show, :id => @user.person.to_param - assigns(:person).should == @user.person + expect(assigns(:person)).to eq(@user.person) end it "assigns all the user's posts" do - @user.posts.should be_empty + expect(@user.posts).to be_empty @user.post(:status_message, :text => "to one aspect", :to => @aspect.id) @user.post(:status_message, :text => "to all aspects", :to => 'all') @user.post(:status_message, :text => "public", :to => 'all', :public => true) - @user.reload.posts.length.should == 3 + expect(@user.reload.posts.length).to eq(3) get :show, :id => @user.person.to_param - assigns(:stream).posts.map(&:id).should =~ @user.posts.map(&:id) + expect(assigns(:stream).posts.map(&:id)).to match_array(@user.posts.map(&:id)) end it "renders the comments on the user's posts" do message = @user.post :status_message, :text => 'test more', :to => @aspect.id @user.comment!(message, 'I mean it') get :show, :id => @user.person.to_param - response.should be_success + expect(response).to be_success end end @@ -243,12 +243,12 @@ describe PeopleController do it "succeeds" do get :show, :id => @person.to_param - response.status.should == 200 + expect(response.status).to eq(200) end it 'succeeds on the mobile site' do get :show, :id => @person.to_param, :format => :mobile - response.should be_success + expect(response).to be_success end context 'with posts' do @@ -265,17 +265,17 @@ describe PeopleController do it "posts include reshares" do reshare = @user.post(:reshare, :public => true, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => alice.aspect_ids) get :show, :id => @user.person.to_param - assigns[:stream].posts.map { |x| x.id }.should include(reshare.id) + expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id) end it "assigns only public posts" do get :show, :id => @person.to_param - assigns[:stream].posts.map(&:id).should =~ @public_posts.map(&:id) + expect(assigns[:stream].posts.map(&:id)).to match_array(@public_posts.map(&:id)) end it 'is sorted by created_at desc' do get :show, :id => @person.to_param - assigns[:stream].stream_posts.should == @public_posts.sort_by { |p| p.created_at }.reverse + expect(assigns[:stream].stream_posts).to eq(@public_posts.sort_by { |p| p.created_at }.reverse) end end @@ -283,8 +283,8 @@ describe PeopleController do p = FactoryGirl.create(:person) get :show, :id => p.to_param - response.should be_redirect - response.should redirect_to new_user_session_path + expect(response).to be_redirect + expect(response).to redirect_to new_user_session_path end end @@ -295,16 +295,16 @@ describe PeopleController do it "succeeds" do get :show, :id => @person.to_param - response.should be_success + expect(response).to be_success end it 'succeeds on the mobile site' do get :show, :id => @person.to_param, :format => :mobile - response.should be_success + expect(response).to be_success end it "assigns only the posts the current user can see" do - bob.posts.should be_empty + expect(bob.posts).to be_empty posts_user_can_see = [] aspect_user_is_in = bob.aspects.where(:name => "generic").first aspect_user_is_not_in = bob.aspects.where(:name => "empty").first @@ -312,16 +312,16 @@ describe PeopleController do bob.post(:status_message, :text => "to an aspect @user is not in", :to => aspect_user_is_not_in.id) posts_user_can_see << bob.post(:status_message, :text => "to all aspects", :to => 'all') posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true) - bob.reload.posts.length.should == 4 + expect(bob.reload.posts.length).to eq(4) get :show, :id => @person.to_param - assigns(:stream).posts.map(&:id).should =~ posts_user_can_see.map(&:id) + expect(assigns(:stream).posts.map(&:id)).to match_array(posts_user_can_see.map(&:id)) end it "posts include reshares" do reshare = @user.post(:reshare, :public => true, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => alice.aspect_ids) get :show, :id => @user.person.to_param - assigns[:stream].posts.map { |x| x.id }.should include(reshare.id) + expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id) end it 'marks a corresponding notifications as read' do @@ -341,29 +341,29 @@ describe PeopleController do it "succeeds" do get :show, :id => @person.to_param - response.should be_success + expect(response).to be_success end it 'succeeds on the mobile site' do get :show, :id => @person.to_param, :format => :mobile - response.should be_success + expect(response).to be_success end it "assigns only public posts" do - eve.posts.should be_empty + expect(eve.posts).to be_empty eve.post(:status_message, :text => "to an aspect @user is not in", :to => eve.aspects.first.id) eve.post(:status_message, :text => "to all aspects", :to => 'all') public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true) - eve.reload.posts.length.should == 3 + expect(eve.reload.posts.length).to eq(3) get :show, :id => @person.to_param - assigns[:stream].posts.map(&:id).should =~ [public_post].map(&:id) + expect(assigns[:stream].posts.map(&:id)).to match_array([public_post].map(&:id)) end it "posts include reshares" do reshare = @user.post(:reshare, :public => true, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => alice.aspect_ids) get :show, :id => @user.person.to_param - assigns[:stream].posts.map { |x| x.id }.should include(reshare.id) + expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id) end end end @@ -377,12 +377,12 @@ describe PeopleController do it 'redirects html requests' do get :hovercard, :person_id => @hover_test.guid - response.should redirect_to person_path(:id => @hover_test.guid) + expect(response).to redirect_to person_path(:id => @hover_test.guid) end it 'returns json with profile stuff' do get :hovercard, :person_id => @hover_test.guid, :format => 'json' - JSON.parse( response.body )['handle'].should == @hover_test.diaspora_handle + expect(JSON.parse( response.body )['handle']).to eq(@hover_test.diaspora_handle) end end @@ -397,16 +397,16 @@ describe PeopleController do describe 'via json' do it 'returns a zero count when a search fails' do get :refresh_search, :q => "weweweKorth", :format => 'json' - response.body.should == {:search_count=>0, :search_html=>""}.to_json + expect(response.body).to eq({:search_count=>0, :search_html=>""}.to_json) end it 'returns with a zero count unless a fully composed name is sent' do get :refresh_search, :q => "Korth" - response.body.should == {:search_count=>0, :search_html=>""}.to_json + expect(response.body).to eq({:search_count=>0, :search_html=>""}.to_json) end it 'returns with a found name' do get :refresh_search, :q => @korth.diaspora_handle - JSON.parse( response.body )["search_count"].should == 1 + expect(JSON.parse( response.body )["search_count"]).to eq(1) end end end @@ -417,48 +417,48 @@ describe PeopleController do contact = alice.contact_for(bob.person) contacts = contact.contacts get :contacts, :person_id => bob.person.to_param - assigns(:contacts_of_contact).should =~ contacts - response.should be_success + expect(assigns(:contacts_of_contact).to_a).to eq(contacts.to_a) + expect(response).to be_success end it 'shows an error when invalid person id' do get :contacts, :person_id => 'foo' - flash[:error].should be_present - response.should redirect_to people_path + expect(flash[:error]).to be_present + expect(response).to redirect_to people_path end end describe '#diaspora_id?' do it 'returns true for pods on urls' do - @controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de").should be true + expect(@controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de")).to be true end it 'returns true for pods on urls with port' do - @controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de:12314").should be true + expect(@controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de:12314")).to be true end it 'returns true for pods on localhost' do - @controller.send(:diaspora_id?, "ilya_123@localhost").should be true + expect(@controller.send(:diaspora_id?, "ilya_123@localhost")).to be true end it 'returns true for pods on localhost and port' do - @controller.send(:diaspora_id?, "ilya_123@localhost:1234").should be true + expect(@controller.send(:diaspora_id?, "ilya_123@localhost:1234")).to be true end it 'returns true for pods on ip' do - @controller.send(:diaspora_id?, "ilya_123@1.1.1.1").should be true + expect(@controller.send(:diaspora_id?, "ilya_123@1.1.1.1")).to be true end it 'returns true for pods on ip and port' do - @controller.send(:diaspora_id?, "ilya_123@1.2.3.4:1234").should be true + expect(@controller.send(:diaspora_id?, "ilya_123@1.2.3.4:1234")).to be true end it 'returns false for pods on with invalid url characters' do - @controller.send(:diaspora_id?, "ilya_123@join_diaspora.com").should be false + expect(@controller.send(:diaspora_id?, "ilya_123@join_diaspora.com")).to be false end it 'returns false for invalid usernames' do - @controller.send(:diaspora_id?, "ilya_2%3@joindiaspora.com").should be false + expect(@controller.send(:diaspora_id?, "ilya_2%3@joindiaspora.com")).to be false end end end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 75a6ece3754e1f627588215bbff85281b578180b..a2316b1b5931d111d84cd1c96f286eed9f33766d 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PhotosController do +describe PhotosController, :type => :controller do before do @alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id, :public => false) @bobs_photo = bob.post(:photo, :user_file => uploaded_photo, :to => bob.aspects.first.id, :public => true) @@ -25,53 +25,53 @@ describe PhotosController do end it 'accepts a photo from a regular form submission' do - lambda { + expect { post :create, @params - }.should change(Photo, :count).by(1) + }.to change(Photo, :count).by(1) end it 'returns application/json when possible' do request.env['HTTP_ACCEPT'] = 'application/json' - post(:create, @params).headers['Content-Type'].should match 'application/json.*' + expect(post(:create, @params).headers['Content-Type']).to match 'application/json.*' end it 'returns text/html by default' do request.env['HTTP_ACCEPT'] = 'text/html,*/*' - post(:create, @params).headers['Content-Type'].should match 'text/html.*' + expect(post(:create, @params).headers['Content-Type']).to match 'text/html.*' end end describe '#create' do before do - @controller.stub(:file_handler).and_return(uploaded_photo) + allow(@controller).to receive(:file_handler).and_return(uploaded_photo) @params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} } end it "creates a photo" do - lambda { + expect { post :create, @params - }.should change(Photo, :count).by(1) + }.to change(Photo, :count).by(1) end it "doesn't allow mass assignment of person" do new_user = FactoryGirl.create(:user) @params[:photo][:author] = new_user post :create, @params - Photo.last.author.should == alice.person + expect(Photo.last.author).to eq(alice.person) end it "doesn't allow mass assignment of person_id" do new_user = FactoryGirl.create(:user) @params[:photo][:author_id] = new_user.id post :create, @params - Photo.last.author.should == alice.person + expect(Photo.last.author).to eq(alice.person) end it 'can set the photo as the profile photo' do old_url = alice.person.profile.image_url @params[:photo][:set_profile_photo] = true post :create, @params - alice.reload.person.profile.image_url.should_not == old_url + expect(alice.reload.person.profile.image_url).not_to eq(old_url) end end @@ -79,26 +79,26 @@ describe PhotosController do it "succeeds without any available pictures" do get :index, :person_id => FactoryGirl.create(:person).guid.to_s - response.should be_success + expect(response).to be_success end it "displays the logged in user's pictures" do get :index, :person_id => alice.person.guid.to_s - assigns[:person].should == alice.person - assigns[:posts].should == [@alices_photo] + expect(assigns[:person]).to eq(alice.person) + expect(assigns[:posts]).to eq([@alices_photo]) end it "displays another person's pictures" do get :index, :person_id => bob.person.guid.to_s - assigns[:person].should == bob.person - assigns[:posts].should == [@bobs_photo] + expect(assigns[:person]).to eq(bob.person) + expect(assigns[:posts]).to eq([@bobs_photo]) end it "returns json when requested" do request.env['HTTP_ACCEPT'] = 'application/json' get :index, :person_id => alice.person.guid.to_s - response.headers['Content-Type'].should match 'application/json.*' + expect(response.headers['Content-Type']).to match 'application/json.*' save_fixture(response.body, "photos_json") end @@ -107,88 +107,88 @@ describe PhotosController do get :index, person_id: bob.person.guid.to_s, max_time: max_time.to_i - assigns[:posts].should be_empty + expect(assigns[:posts]).to be_empty end end describe '#edit' do it "succeeds when user owns the photo" do get :edit, :id => @alices_photo.id - response.should be_success + expect(response).to be_success end it "redirects when the user does not own the photo" do get :edit, :id => @bobs_photo.id - response.should redirect_to(:action => :index, :person_id => alice.person.guid.to_s) + expect(response).to redirect_to(:action => :index, :person_id => alice.person.guid.to_s) end end describe '#destroy' do it 'let a user delete his message' do delete :destroy, :id => @alices_photo.id - Photo.find_by_id(@alices_photo.id).should be_nil + expect(Photo.find_by_id(@alices_photo.id)).to be_nil end it 'will let you delete your profile picture' do xhr :get, :make_profile_photo, :photo_id => @alices_photo.id, :format => :js delete :destroy, :id => @alices_photo.id - Photo.find_by_id(@alices_photo.id).should be_nil + expect(Photo.find_by_id(@alices_photo.id)).to be_nil end it 'sends a retraction on delete' do - @controller.stub(:current_user).and_return(alice) - alice.should_receive(:retract).with(@alices_photo) + allow(@controller).to receive(:current_user).and_return(alice) + expect(alice).to receive(:retract).with(@alices_photo) delete :destroy, :id => @alices_photo.id end it 'will not let you destroy posts visible to you' do delete :destroy, :id => @bobs_photo.id - Photo.find_by_id(@bobs_photo.id).should be_truthy + expect(Photo.find_by_id(@bobs_photo.id)).to be_truthy end it 'will not let you destroy posts you do not own' do eves_photo = eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true) delete :destroy, :id => eves_photo.id - Photo.find_by_id(eves_photo.id).should be_truthy + expect(Photo.find_by_id(eves_photo.id)).to be_truthy end end describe "#update" do it "updates the caption of a photo" do put :update, :id => @alices_photo.id, :photo => { :text => "now with lasers!" }, :format => :js - @alices_photo.reload.text.should == "now with lasers!" + expect(@alices_photo.reload.text).to eq("now with lasers!") end it "doesn't allow mass assignment of person" do new_user = FactoryGirl.create(:user) params = { :text => "now with lasers!", :author => new_user } put :update, :id => @alices_photo.id, :photo => params, :format => :js - @alices_photo.reload.author.should == alice.person + expect(@alices_photo.reload.author).to eq(alice.person) end it "doesn't allow mass assignment of person_id" do new_user = FactoryGirl.create(:user) params = { :text => "now with lasers!", :author_id => new_user.id } put :update, :id => @alices_photo.id, :photo => params, :format => :js - @alices_photo.reload.author_id.should == alice.person.id + expect(@alices_photo.reload.author_id).to eq(alice.person.id) end it 'redirects if you do not have access to the post' do params = { :text => "now with lasers!" } put :update, :id => @bobs_photo.id, :photo => params - response.should redirect_to(:action => :index, :person_id => alice.person.guid.to_s) + expect(response).to redirect_to(:action => :index, :person_id => alice.person.guid.to_s) end end describe "#make_profile_photo" do it 'should return a 201 on a js success' do xhr :get, :make_profile_photo, :photo_id => @alices_photo.id, :format => 'js' - response.code.should == "201" + expect(response.code).to eq("201") end it 'should return a 422 on failure' do get :make_profile_photo, :photo_id => @bobs_photo.id - response.code.should == "422" + expect(response.code).to eq("422") end end @@ -201,7 +201,7 @@ describe PhotosController do it 'should return 200 for existing stuff on mobile devices' do get :show, :person_id => alice.person.guid, :id => @alices_photo.id, :format => 'mobile' - response.should be_success + expect(response).to be_success end it "doesn't leak private photos to the public" do diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 0d424ecd2e21506fd33400e8b7eec46b8e6612ba..e3f7a6071cbd2ac41f8091f4bf1f25f09c08a042 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PostsController do +describe PostsController, :type => :controller do before do aspect = alice.aspects.first @message = alice.build_post :status_message, :text => "ohai", :to => aspect.id @@ -22,22 +22,22 @@ describe PostsController do it 'succeeds' do get :show, "id" => @message.id - response.should be_success + expect(response).to be_success end it 'succeeds on mobile' do get :show, "id" => @message.id - response.should be_success + expect(response).to be_success end it 'renders the application layout on mobile' do get :show, :id => @message.id, :format => :mobile - response.should render_template('layouts/application') + expect(response).to render_template('layouts/application') end it 'succeeds on mobile with a reshare' do get :show, "id" => FactoryGirl.create(:reshare, :author => alice.person).id, :format => :mobile - response.should be_success + expect(response).to be_success end it 'marks a corresponding notifications as read' do @@ -76,25 +76,25 @@ describe PostsController do it 'shows a public post' do get :show, :id => @status.id - response.status.should == 200 + expect(response.status).to eq(200) end it 'succeeds for statusnet' do @request.env["HTTP_ACCEPT"] = "application/html+xml,text/html" get :show, :id => @status.id - response.should be_success + expect(response).to be_success end it 'responds with diaspora xml if format is xml' do get :show, :id => @status.guid, :format => :xml - response.body.should == @status.to_diaspora_xml + expect(response.body).to eq(@status.to_diaspora_xml) end end it 'does not show a private post' do status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all') get :show, :id => status.id - response.status.should == 404 + expect(response.status).to eq(404) end # We want to be using guids from now on for this post route, but do not want to break @@ -107,20 +107,20 @@ describe PostsController do it 'assumes guids less than 8 chars are ids and not guids' do p = Post.where(:id => @status.id.to_s) - Post.should_receive(:where) + expect(Post).to receive(:where) .with(hash_including(:id => @status.id.to_s)) .and_return(p) get :show, :id => @status.id - response.should be_success + expect(response).to be_success end it 'assumes guids more than (or equal to) 8 chars are actually guids' do p = Post.where(:guid => @status.guid) - Post.should_receive(:where) + expect(Post).to receive(:where) .with(hash_including(:guid => @status.guid)) .and_return(p) get :show, :id => @status.guid - response.should be_success + expect(response).to be_success end end end @@ -129,7 +129,7 @@ describe PostsController do describe 'iframe' do it 'contains an iframe' do get :iframe, :id => @message.id - response.body.should match /iframe/ + expect(response.body).to match /iframe/ end end @@ -137,12 +137,12 @@ describe PostsController do it 'works when you can see it' do sign_in alice get :oembed, :url => "/posts/#{@message.id}" - response.body.should match /iframe/ + expect(response.body).to match /iframe/ end it 'returns a 404 response when the post is not found' do get :oembed, :url => "/posts/#{@message.id}" - response.status.should == 404 + expect(response.status).to eq(404) end end @@ -154,28 +154,28 @@ describe PostsController do it 'let a user delete his message' do message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id) delete :destroy, :format => :js, :id => message.id - response.should be_success - StatusMessage.find_by_id(message.id).should be_nil + expect(response).to be_success + expect(StatusMessage.find_by_id(message.id)).to be_nil end it 'sends a retraction on delete' do - controller.stub(:current_user).and_return alice + allow(controller).to receive(:current_user).and_return alice message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id) - alice.should_receive(:retract).with(message) + expect(alice).to receive(:retract).with(message) delete :destroy, :format => :js, :id => message.id - response.should be_success + expect(response).to be_success end it 'will not let you destroy posts visible to you' do message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id) expect { delete :destroy, :format => :js, :id => message.id }.to raise_error(ActiveRecord::RecordNotFound) - StatusMessage.exists?(message.id).should be true + expect(StatusMessage.exists?(message.id)).to be true end it 'will not let you destory posts you do not own' do message = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id) expect { delete :destroy, :format => :js, :id => message.id }.to raise_error(ActiveRecord::RecordNotFound) - StatusMessage.exists?(message.id).should be true + expect(StatusMessage.exists?(message.id)).to be true end end end diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 6655e29c8c9dd796d6a6bc0666da67c851d090c7..c32878c6ed3c36a6e2214cfe7a51b9e91aa23579 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ProfilesController do +describe ProfilesController, :type => :controller do before do sign_in :user, eve end @@ -14,33 +14,33 @@ describe ProfilesController do let(:mock_presenter) { double(:as_json => {:rock_star => "Jamie Cai"})} it "returns a post Presenter" do - Person.should_receive(:find_by_guid!).with("12345").and_return(mock_person) - PersonPresenter.should_receive(:new).with(mock_person, eve).and_return(mock_presenter) + expect(Person).to receive(:find_by_guid!).with("12345").and_return(mock_person) + expect(PersonPresenter).to receive(:new).with(mock_person, eve).and_return(mock_presenter) get :show, :id => 12345, :format => :json - response.body.should == {:rock_star => "Jamie Cai"}.to_json + expect(response.body).to eq({:rock_star => "Jamie Cai"}.to_json) end end describe '#edit' do it 'succeeds' do get :edit - response.should be_success + expect(response).to be_success end it 'sets the profile to the current users profile' do get :edit - assigns[:profile].should == eve.person.profile + expect(assigns[:profile]).to eq(eve.person.profile) end it 'sets the aspect to "person_edit" ' do get :edit - assigns[:aspect].should == :person_edit + expect(assigns[:aspect]).to eq(:person_edit) end it 'sets the person to the current users person' do get :edit - assigns[:person].should == eve.person + expect(assigns[:person]).to eq(eve.person) end end @@ -51,22 +51,22 @@ describe ProfilesController do :first_name => "Will", :last_name => "Smith" } - flash[:notice].should_not be_blank + expect(flash[:notice]).not_to be_blank end it "sets nsfw" do - eve.person(true).profile.nsfw.should == false + expect(eve.person(true).profile.nsfw).to eq(false) put :update, :profile => { :id => eve.person.id, :nsfw => "1" } - eve.person(true).profile.nsfw.should == true + expect(eve.person(true).profile.nsfw).to eq(true) end it "unsets nsfw" do eve.person.profile.nsfw = true eve.person.profile.save - eve.person(true).profile.nsfw.should == true + expect(eve.person(true).profile.nsfw).to eq(true) put :update, :profile => { :id => eve.person.id } - eve.person(true).profile.nsfw.should == false + expect(eve.person(true).profile.nsfw).to eq(false) end it 'sets tags' do @@ -75,7 +75,7 @@ describe ProfilesController do :profile => {:tag_string => ''} } put :update, params - eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges'].to_set + expect(eve.person(true).profile.tag_list.to_set).to eq(['apples', 'oranges'].to_set) end it 'sets plaintext tags' do @@ -84,7 +84,7 @@ describe ProfilesController do :profile => {:tag_string => '#pears'} } put :update, params - eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'pears'].to_set + expect(eve.person(true).profile.tag_list.to_set).to eq(['apples', 'oranges', 'pears'].to_set) end it 'sets plaintext tags without #' do @@ -93,7 +93,7 @@ describe ProfilesController do :profile => {:tag_string => 'bananas'} } put :update, params - eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'bananas'].to_set + expect(eve.person(true).profile.tag_list.to_set).to eq(['apples', 'oranges', 'bananas'].to_set) end it 'sets valid birthday' do @@ -105,9 +105,9 @@ describe ProfilesController do :day => '28' } } } put :update, params - eve.person(true).profile.birthday.year.should == 2001 - eve.person(true).profile.birthday.month.should == 2 - eve.person(true).profile.birthday.day.should == 28 + expect(eve.person(true).profile.birthday.year).to eq(2001) + expect(eve.person(true).profile.birthday.month).to eq(2) + expect(eve.person(true).profile.birthday.day).to eq(28) end it 'displays error for invalid birthday' do @@ -119,7 +119,7 @@ describe ProfilesController do :day => '31' } } } put :update, params - flash[:error].should_not be_blank + expect(flash[:error]).not_to be_blank end context 'with a profile photo set' do @@ -138,7 +138,7 @@ describe ProfilesController do image_url = eve.person.profile.image_url put :update, @params - Person.find(eve.person.id).profile.image_url.should == image_url + expect(Person.find(eve.person.id).profile.image_url).to eq(image_url) end end @@ -153,12 +153,12 @@ describe ProfilesController do person = eve.person profile = person.profile put :update, @profile_params - profile.reload.person_id.should == person.id + expect(profile.reload.person_id).to eq(person.id) end it 'diaspora handle' do put :update, @profile_params - Person.find(eve.person.id).profile[:diaspora_handle].should_not == 'abc@a.com' + expect(Person.find(eve.person.id).profile[:diaspora_handle]).not_to eq('abc@a.com') end end end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 16df779509480cb9512f5ee4869207d05171c1d3..08415577af2454e87cf3f86df7758d906e08ed91 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PublicsController do +describe PublicsController, :type => :controller do let(:fixture_path) { Rails.root.join('spec', 'fixtures') } before do @user = alice @@ -14,8 +14,8 @@ describe PublicsController do describe '#host_meta' do it 'succeeds', :fixture => true do get :host_meta - response.should be_success - response.body.should =~ /webfinger/ + expect(response).to be_success + expect(response.body).to match(/webfinger/) save_fixture(response.body, "host-meta", fixture_path) end end @@ -23,17 +23,17 @@ describe PublicsController do describe '#receive_public' do it 'succeeds' do post :receive_public, :xml => "<stuff/>" - response.should be_success + expect(response).to be_success end it 'returns a 422 if no xml is passed' do post :receive_public - response.code.should == '422' + expect(response.code).to eq('422') end it 'enqueues a ReceiveUnencryptedSalmon job' do xml = "stuff" - Workers::ReceiveUnencryptedSalmon.should_receive(:perform_async).with(xml) + expect(Workers::ReceiveUnencryptedSalmon).to receive(:perform_async).with(xml) post :receive_public, :xml => xml end end @@ -43,11 +43,11 @@ describe PublicsController do it 'succeeds' do post :receive, "guid" => @user.person.guid.to_s, "xml" => xml - response.should be_success + expect(response).to be_success end it 'enqueues a receive job' do - Workers::ReceiveEncryptedSalmon.should_receive(:perform_async).with(@user.id, xml).once + expect(Workers::ReceiveEncryptedSalmon).to receive(:perform_async).with(@user.id, xml).once post :receive, "guid" => @user.person.guid.to_s, "xml" => xml end @@ -60,90 +60,90 @@ describe PublicsController do salmon_factory = Salmon::EncryptedSlap.create_by_user_and_activity(@user, xml2) enc_xml = salmon_factory.xml_for(user2.person) - Workers::ReceiveEncryptedSalmon.should_receive(:perform_async).with(@user.id, enc_xml).once + expect(Workers::ReceiveEncryptedSalmon).to receive(:perform_async).with(@user.id, enc_xml).once post :receive, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml) end it 'returns a 422 if no xml is passed' do post :receive, "guid" => @person.guid.to_s - response.code.should == '422' + expect(response.code).to eq('422') end it 'returns a 404 if no user is found' do post :receive, "guid" => @person.guid.to_s, "xml" => xml - response.should be_not_found + expect(response).to be_not_found end it 'returns a 404 if no person is found' do post :receive, :guid => '2398rq3948yftn', :xml => xml - response.should be_not_found + expect(response).to be_not_found end end describe '#hcard' do it "succeeds", :fixture => true do post :hcard, "guid" => @user.person.guid.to_s - response.should be_success + expect(response).to be_success save_fixture(response.body, "hcard", fixture_path) end it 'sets the person' do post :hcard, "guid" => @user.person.guid.to_s - assigns[:person].should == @user.person + expect(assigns[:person]).to eq(@user.person) end it 'does not query by user id' do post :hcard, "guid" => 90348257609247856.to_s - assigns[:person].should be_nil - response.should be_not_found + expect(assigns[:person]).to be_nil + expect(response).to be_not_found end it 'finds nothing for closed accounts' do @user.person.update_attributes(:closed_account => true) get :hcard, :guid => @user.person.guid.to_s - response.should be_not_found + expect(response).to be_not_found end end describe '#webfinger' do it "succeeds when the person and user exist locally", :fixture => true do post :webfinger, 'q' => @user.person.diaspora_handle - response.should be_success + expect(response).to be_success save_fixture(response.body, "webfinger", fixture_path) end it "404s when the person exists remotely because it is local only" do stub_success('me@mydiaspora.pod.com') post :webfinger, 'q' => 'me@mydiaspora.pod.com' - response.should be_not_found + expect(response).to be_not_found end it "404s when the person is local but doesn't have an owner" do post :webfinger, 'q' => @person.diaspora_handle - response.should be_not_found + expect(response).to be_not_found end it "404s when the person does not exist locally or remotely" do stub_failure('me@mydiaspora.pod.com') post :webfinger, 'q' => 'me@mydiaspora.pod.com' - response.should be_not_found + expect(response).to be_not_found end it 'has the users profile href' do get :webfinger, :q => @user.diaspora_handle - response.body.should include "http://webfinger.net/rel/profile-page" + expect(response.body).to include "http://webfinger.net/rel/profile-page" end it 'finds nothing for closed accounts' do @user.person.update_attributes(:closed_account => true) get :webfinger, :q => @user.diaspora_handle - response.should be_not_found + expect(response).to be_not_found end end describe '#hub' do it 'succeeds' do get :hub - response.should be_success + expect(response).to be_success end end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index d6a9b28a4ab048cb334b2e87eac678b400866834..2bc0ac92e3e1c534f0cbe68a3d73bdd720fc3d9f 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe RegistrationsController do +describe RegistrationsController, :type => :controller do include Devise::TestHelpers before do @@ -30,25 +30,25 @@ describe RegistrationsController do it 'redirects #new to the login page' do get :new - flash[:error].should == I18n.t('registrations.closed') - response.should redirect_to new_user_session_path + expect(flash[:error]).to eq(I18n.t('registrations.closed')) + expect(response).to redirect_to new_user_session_path end it 'redirects #create to the login page' do post :create, @valid_params - flash[:error].should == I18n.t('registrations.closed') - response.should redirect_to new_user_session_path + expect(flash[:error]).to eq(I18n.t('registrations.closed')) + expect(response).to redirect_to new_user_session_path end it 'does not redirect if there is a valid invite token' do i = InvitationCode.create(:user => bob) get :new, :invite => {:token => i.token} - response.should_not be_redirect + expect(response).not_to be_redirect end it 'does redirect if there is an invalid invite token' do get :new, :invite => {:token => 'fssdfsd'} - response.should be_redirect + expect(response).to be_redirect end end @@ -59,29 +59,29 @@ describe RegistrationsController do before do AppConfig.settings.enable_registrations = true user = FactoryGirl.build(:user) - User.stub(:build).and_return(user) + allow(User).to receive(:build).and_return(user) end it "creates a user" do - lambda { + expect { get :create, @valid_params - }.should change(User, :count).by(1) + }.to change(User, :count).by(1) end it "assigns @user" do get :create, @valid_params - assigns(:user).should be_truthy + expect(assigns(:user)).to be_truthy end it "sets the flash" do get :create, @valid_params - flash[:notice].should_not be_blank + expect(flash[:notice]).not_to be_blank end it "redirects to the home path" do get :create, @valid_params - response.should be_redirect - response.location.should match /^#{stream_url}\??$/ + expect(response).to be_redirect + expect(response.location).to match /^#{stream_url}\??$/ end end @@ -92,21 +92,21 @@ describe RegistrationsController do end it "does not create a user" do - lambda { get :create, @invalid_params }.should_not change(User, :count) + expect { get :create, @invalid_params }.not_to change(User, :count) end it "does not create a person" do - lambda { get :create, @invalid_params }.should_not change(Person, :count) + expect { get :create, @invalid_params }.not_to change(Person, :count) end it "assigns @user" do get :create, @invalid_params - assigns(:user).should_not be_nil + expect(assigns(:user)).not_to be_nil end it "sets the flash error" do get :create, @invalid_params - flash[:error].should_not be_blank + expect(flash[:error]).not_to be_blank end it "renders new" do diff --git a/spec/controllers/report_controller_spec.rb b/spec/controllers/report_controller_spec.rb index 465bc6fd5ebba90a0eaee3e5fcb3bb6e4ac4d289..6e63902e2094e30f67dd376e1ab955330f2ed7fd 100644 --- a/spec/controllers/report_controller_spec.rb +++ b/spec/controllers/report_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ReportController do +describe ReportController, :type => :controller do before do sign_in alice @message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id) @@ -15,7 +15,7 @@ describe ReportController do context 'admin not signed in' do it 'is behind redirect_unless_admin' do get :index - response.should redirect_to stream_path + expect(response).to redirect_to stream_path end end @@ -25,7 +25,7 @@ describe ReportController do end it 'succeeds and renders index' do get :index - response.should render_template('index') + expect(response).to render_template('index') end end end @@ -39,15 +39,15 @@ describe ReportController do context 'report offensive post' do it 'succeeds' do put :create, :report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' } - response.status.should == 200 - Report.exists?(:item_id => @message.id, :item_type => 'post').should be true + expect(response.status).to eq(200) + expect(Report.exists?(:item_id => @message.id, :item_type => 'post')).to be true end end context 'report offensive comment' do it 'succeeds' do put :create, :report => { :item_id => @comment.id, :item_type => 'comment', :text => 'offensive content' } - response.status.should == 200 - Report.exists?(:item_id => @comment.id, :item_type => 'comment').should be true + expect(response.status).to eq(200) + expect(Report.exists?(:item_id => @comment.id, :item_type => 'comment')).to be true end end end @@ -56,15 +56,15 @@ describe ReportController do context 'mark post report as user' do it 'is behind redirect_unless_admin' do put :update, :id => @message.id, :type => 'post' - response.should redirect_to stream_path - Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post').should be_truthy + expect(response).to redirect_to stream_path + expect(Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post')).to be_truthy end end context 'mark comment report as user' do it 'is behind redirect_unless_admin' do put :update, :id => @comment.id, :type => 'comment' - response.should redirect_to stream_path - Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment').should be_truthy + expect(response).to redirect_to stream_path + expect(Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment')).to be_truthy end end @@ -74,8 +74,8 @@ describe ReportController do end it 'succeeds' do put :update, :id => @message.id, :type => 'post' - response.status.should == 302 - Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post').should be_truthy + expect(response.status).to eq(302) + expect(Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post')).to be_truthy end end context 'mark comment report as admin' do @@ -84,8 +84,8 @@ describe ReportController do end it 'succeeds' do put :update, :id => @comment.id, :type => 'comment' - response.status.should == 302 - Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment').should be_truthy + expect(response.status).to eq(302) + expect(Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment')).to be_truthy end end end @@ -94,15 +94,15 @@ describe ReportController do context 'destroy post as user' do it 'is behind redirect_unless_admin' do delete :destroy, :id => @message.id, :type => 'post' - response.should redirect_to stream_path - Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post').should be_truthy + expect(response).to redirect_to stream_path + expect(Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post')).to be_truthy end end context 'destroy comment as user' do it 'is behind redirect_unless_admin' do delete :destroy, :id => @comment.id, :type => 'comment' - response.should redirect_to stream_path - Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment').should be_truthy + expect(response).to redirect_to stream_path + expect(Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment')).to be_truthy end end @@ -112,8 +112,8 @@ describe ReportController do end it 'succeeds' do delete :destroy, :id => @message.id, :type => 'post' - response.status.should == 302 - Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post').should be_truthy + expect(response.status).to eq(302) + expect(Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post')).to be_truthy end end context 'destroy comment as admin' do @@ -122,8 +122,8 @@ describe ReportController do end it 'succeeds' do delete :destroy, :id => @comment.id, :type => 'comment' - response.status.should == 302 - Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment').should be_truthy + expect(response.status).to eq(302) + expect(Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment')).to be_truthy end end end diff --git a/spec/controllers/reshares_controller_spec.rb b/spec/controllers/reshares_controller_spec.rb index 180f9f6e8234bf48ba2db02d656b22efa3775c80..aa21badaeaf9c2e418a7c9900ec5254529d09a71 100644 --- a/spec/controllers/reshares_controller_spec.rb +++ b/spec/controllers/reshares_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ResharesController do +describe ResharesController, :type => :controller do describe '#create' do let(:post_request!) { post :create, :format => :json, :root_guid => @post_guid @@ -13,17 +13,17 @@ describe ResharesController do it 'requires authentication' do post_request! - response.should_not be_success + expect(response).not_to be_success end context 'with an authenticated user' do before do sign_in :user, bob - @controller.stub(:current_user).and_return(bob) + allow(@controller).to receive(:current_user).and_return(bob) end it 'succeeds' do - response.should be_success + expect(response).to be_success post_request! end @@ -34,12 +34,12 @@ describe ResharesController do end it 'after save, calls add to streams' do - bob.should_receive(:add_to_streams) + expect(bob).to receive(:add_to_streams) post_request! end it 'calls dispatch' do - bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers)) + expect(bob).to receive(:dispatch_post).with(anything, hash_including(:additional_subscribers)) post_request! end @@ -50,8 +50,8 @@ describe ResharesController do it 'doesn\'t allow the user to reshare the post again' do post_request! - response.code.should == '422' - response.body.strip.should be_empty + expect(response.code).to eq('422') + expect(response.body.strip).to be_empty end end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index e048c376d432a0a0b61708aef9d5f08c41527ce9..5ec4baf6d5a28019d2914918db1eaa3e5552bcd9 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SearchController do +describe SearchController, :type => :controller do before do @user = alice @aspect = @user.aspects.first @@ -13,7 +13,7 @@ describe SearchController do :last_name => "w", :searchable => false)) it 'goes to people index page' do get :search, :q => 'eugene' - response.should be_redirect + expect(response).to be_redirect end end @@ -21,17 +21,17 @@ describe SearchController do describe 'query is a tag' do it 'goes to a tag page' do get :search, :q => '#cats' - response.should redirect_to(tag_path('cats')) + expect(response).to redirect_to(tag_path('cats')) end it 'removes dots from the query' do get :search, :q => '#cat.s' - response.should redirect_to(tag_path('cats')) + expect(response).to redirect_to(tag_path('cats')) end it 'stay on the page if you search for the empty hash' do get :search, :q => '#' - flash[:error].should be_present + expect(flash[:error]).to be_present end end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 0796a9f4e7fdb72ed5400e151a4d477e02f6c7df..89cbf844805dce2b5c1b3bf2bb3a868b03a3a744 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ServicesController do +describe ServicesController, :type => :controller do let(:omniauth_auth) do { 'provider' => 'facebook', 'uid' => '2', @@ -15,7 +15,7 @@ describe ServicesController do before do sign_in :user, user - @controller.stub(:current_user).and_return(user) + allow(@controller).to receive(:current_user).and_return(user) end describe '#index' do @@ -25,7 +25,7 @@ describe ServicesController do it "displays user's connected services" do get :index - assigns[:services].should == user.services + expect(assigns[:services]).to eq(user.services) end end @@ -43,7 +43,7 @@ describe ServicesController do it 'saves the provider' do post :create, :provider => 'facebook' - user.reload.services.first.class.name.should == "Services::Facebook" + expect(user.reload.services.first.class.name).to eq("Services::Facebook") end context 'when service exists with the same uid' do @@ -52,13 +52,13 @@ describe ServicesController do it 'doesnt create a new service' do service_count = Service.count post :create, :provider => 'twitter' - Service.count.should == service_count + expect(Service.count).to eq(service_count) end it 'flashes an already_authorized error with the diaspora handle for the user' do post :create, :provider => 'twitter' - flash[:error].include?(user.profile.diaspora_handle).should be true - flash[:error].include?( 'already authorized' ).should be true + expect(flash[:error].include?(user.profile.diaspora_handle)).to be true + expect(flash[:error].include?( 'already authorized' )).to be true end end @@ -78,12 +78,12 @@ describe ServicesController do it 'doesnt create a new service' do service_count = Service.count post :create, :provider => 'twitter' - Service.count.should == service_count + expect(Service.count).to eq(service_count) end it 'flashes an read-only access error' do post :create, :provider => 'twitter' - flash[:error].include?( 'Access level is read-only' ).should be true + expect(flash[:error].include?( 'Access level is read-only' )).to be true end end end @@ -110,17 +110,17 @@ describe ServicesController do end it 'does not queue a job if the profile photo is set' do - @controller.stub(:no_profile_image?).and_return false + allow(@controller).to receive(:no_profile_image?).and_return false - Workers::FetchProfilePhoto.should_not_receive(:perform_async) + expect(Workers::FetchProfilePhoto).not_to receive(:perform_async) post :create, :provider => 'twitter' end it 'queues a job to save user photo if the photo does not exist' do - @controller.stub(:no_profile_image?).and_return true + allow(@controller).to receive(:no_profile_image?).and_return true - Workers::FetchProfilePhoto.should_receive(:perform_async).with(user.id, anything(), "https://service.com/fallback_lowres.jpg") + expect(Workers::FetchProfilePhoto).to receive(:perform_async).with(user.id, anything(), "https://service.com/fallback_lowres.jpg") post :create, :provider => 'twitter' end @@ -133,9 +133,9 @@ describe ServicesController do end it 'destroys a service selected by id' do - lambda{ + expect{ delete :destroy, :id => @service1.id - }.should change(user.services, :count).by(-1) + }.to change(user.services, :count).by(-1) end end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 3efcb616b3a09ba525c039883269253dc77a8cf3..fba0810f82479c1fc5867fb0b3b0f2d36930de7e 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe SessionsController do +describe SessionsController, :type => :controller do include Devise::TestHelpers let(:mock_access_token) { Object.new } @@ -20,15 +20,15 @@ describe SessionsController do describe "#create" do it "redirects to /stream for a non-mobile user" do post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} - response.should be_redirect - response.location.should match /^#{stream_url}\??$/ + expect(response).to be_redirect + expect(response.location).to match /^#{stream_url}\??$/ end it "redirects to /stream for a mobile user" do @request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7' post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} - response.should be_redirect - response.location.should match /^#{stream_url}\??$/ + expect(response).to be_redirect + expect(response.location).to match /^#{stream_url}\??$/ end end @@ -38,13 +38,13 @@ describe SessionsController do end it "redirects to / for a non-mobile user" do delete :destroy - response.should redirect_to new_user_session_path + expect(response).to redirect_to new_user_session_path end it "redirects to / for a mobile user" do @request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7' delete :destroy - response.should redirect_to root_path + expect(response).to redirect_to root_path end end end diff --git a/spec/controllers/share_visibilities_controller_spec.rb b/spec/controllers/share_visibilities_controller_spec.rb index fce516f7b0a184f33dba932b3b50c92347ecfa7f..5fe1bb11b79ff5e691d2b5e66f8bed0a5e9d356d 100644 --- a/spec/controllers/share_visibilities_controller_spec.rb +++ b/spec/controllers/share_visibilities_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ShareVisibilitiesController do +describe ShareVisibilitiesController, :type => :controller do before do @status = alice.post(:status_message, :text => "hello", :to => alice.aspects.first) sign_in :user, bob @@ -14,11 +14,11 @@ describe ShareVisibilitiesController do context "on a post you can see" do it 'succeeds' do put :update, :format => :js, :id => 42, :post_id => @status.id - response.should be_success + expect(response).to be_success end it 'it calls toggle_hidden_shareable' do - @controller.current_user.should_receive(:toggle_hidden_shareable).with(an_instance_of(Post)) + expect(@controller.current_user).to receive(:toggle_hidden_shareable).with(an_instance_of(Post)) put :update, :format => :js, :id => 42, :post_id => @status.id end end @@ -30,7 +30,7 @@ describe ShareVisibilitiesController do @controller.params[:post_id] = id @controller.params[:shareable_type] = 'Post' - Post.should_receive(:where).with(hash_including(:id => id)).once.and_return(double.as_null_object) + expect(Post).to receive(:where).with(hash_including(:id => id)).once.and_return(double.as_null_object) 2.times do |n| @controller.send(:accessible_post) end diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 8fb06c1220a13268ef339c04dda97a8b76317f64..6d756671477700d18563af3eeeacab4b6ea5d151 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -4,19 +4,19 @@ require 'spec_helper' -describe StatisticsController do +describe StatisticsController, :type => :controller do describe '#statistics' do it 'responds to format json' do get :statistics, :format => 'json' - response.code.should == '200' + expect(response.code).to eq('200') end it 'contains json' do get :statistics, :format => 'json' json = JSON.parse(response.body) - json['name'].should be_present + expect(json['name']).to be_present end end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 061e3832c259bcbe83143f4b4cb2f7c7ba788fa6..cfeacd606b171eb2805b2d5c3bc6515360b4ea3a 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -4,47 +4,47 @@ require 'spec_helper' -describe StatusMessagesController do +describe StatusMessagesController, :type => :controller do before do @aspect1 = alice.aspects.first request.env["HTTP_REFERER"] = "" sign_in :user, alice - @controller.stub(:current_user).and_return(alice) + allow(@controller).to receive(:current_user).and_return(alice) alice.reload end describe '#bookmarklet' do it 'succeeds' do get :bookmarklet - response.should be_success + expect(response).to be_success end it 'contains a complete html document' do get :bookmarklet doc = Nokogiri(response.body) - doc.xpath('//head').count.should equal 1 - doc.xpath('//body').count.should equal 1 + expect(doc.xpath('//head').count).to equal 1 + expect(doc.xpath('//body').count).to equal 1 end it 'accepts get params' do get :bookmarklet, { url: 'https://www.youtube.com/watch?v=0Bmhjf0rKe8', title: 'Surprised Kitty', notes: 'cute kitty' } - response.should be_success + expect(response).to be_success end end describe '#new' do it 'succeeds' do get :new, :person_id => bob.person.id - response.should be_success + expect(response).to be_success end it 'should redirect on desktop version' do get :new - response.should redirect_to(stream_path) + expect(response).to redirect_to(stream_path) end it 'generates a jasmine fixture', :fixture => true do @@ -68,51 +68,51 @@ describe StatusMessagesController do it 'creates with valid html' do post :create, status_message_hash - response.status.should == 302 - response.should be_redirect + expect(response.status).to eq(302) + expect(response).to be_redirect end it 'creates with invalid html' do post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }) - response.status.should == 302 - response.should be_redirect + expect(response.status).to eq(302) + expect(response).to be_redirect end it 'creates with valid json' do post :create, status_message_hash.merge(:format => 'json') - response.status.should == 201 + expect(response.status).to eq(201) end it 'creates with invalid json' do post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }, :format => 'json') - response.status.should == 403 + expect(response.status).to eq(403) end it 'creates with valid mobile' do post :create, status_message_hash.merge(:format => 'mobile') - response.status.should == 302 - response.should be_redirect + expect(response.status).to eq(302) + expect(response).to be_redirect end it 'creates with invalid mobile' do post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }, :format => 'mobile') - response.status.should == 302 - response.should be_redirect + expect(response.status).to eq(302) + expect(response).to be_redirect end it 'removes getting started from new users' do - @controller.should_receive(:remove_getting_started) + expect(@controller).to receive(:remove_getting_started) post :create, status_message_hash end it 'takes public in aspect ids' do post :create, status_message_hash.merge(:aspect_ids => ['public']) - response.status.should == 302 + expect(response.status).to eq(302) end it 'takes all_aspects in aspect ids' do post :create, status_message_hash.merge(:aspect_ids => ['all_aspects']) - response.status.should == 302 + expect(response.status).to eq(302) end it "dispatches the post to the specified services" do @@ -121,7 +121,7 @@ describe StatusMessagesController do alice.services << Services::Twitter.new status_message_hash[:services] = ['facebook'] service_types = Service.titles(status_message_hash[:services]) - alice.should_receive(:dispatch_post).with(anything(), hash_including(:service_types => service_types)) + expect(alice).to receive(:dispatch_post).with(anything(), hash_including(:service_types => service_types)) post :create, status_message_hash end @@ -129,7 +129,7 @@ describe StatusMessagesController do s1 = Services::Facebook.new alice.services << s1 status_message_hash[:services] = "facebook" - alice.should_receive(:dispatch_post).with(anything(), hash_including(:service_types => ["Services::Facebook"])) + expect(alice).to receive(:dispatch_post).with(anything(), hash_including(:service_types => ["Services::Facebook"])) post :create, status_message_hash end @@ -137,19 +137,19 @@ describe StatusMessagesController do status_message_hash[:status_message][:author_id] = bob.person.id post :create, status_message_hash new_message = StatusMessage.find_by_text(status_message_hash[:status_message][:text]) - new_message.author_id.should == alice.person.id + expect(new_message.author_id).to eq(alice.person.id) end it "doesn't overwrite id" do old_status_message = alice.post(:status_message, :text => "hello", :to => @aspect1.id) status_message_hash[:status_message][:id] = old_status_message.id post :create, status_message_hash - old_status_message.reload.text.should == 'hello' + expect(old_status_message.reload.text).to eq('hello') end it 'calls dispatch post once subscribers is set' do - alice.should_receive(:dispatch_post){|post, opts| - post.subscribers(alice).should == [bob.person] + expect(alice).to receive(:dispatch_post){|post, opts| + expect(post.subscribers(alice)).to eq([bob.person]) } post :create, status_message_hash end @@ -158,7 +158,7 @@ describe StatusMessagesController do status_message_hash.merge!(:aspect_ids => ['public']) status_message_hash[:status_message].merge!(:provider_display_name => "mobile") post :create, status_message_hash - StatusMessage.first.provider_display_name.should == 'mobile' + expect(StatusMessage.first.provider_display_name).to eq('mobile') end # disabled to fix federation @@ -182,12 +182,12 @@ describe StatusMessagesController do it "will post a photo without text" do @hash.delete :text post :create, @hash - response.should be_redirect + expect(response).to be_redirect end it "attaches all referenced photos" do post :create, @hash - assigns[:status_message].photos.map(&:id).should =~ [@photo1, @photo2].map(&:id) + expect(assigns[:status_message].photos.map(&:id)).to match_array([@photo1, @photo2].map(&:id)) end it "sets the pending bit of referenced photos" do @@ -195,8 +195,8 @@ describe StatusMessagesController do post :create, @hash end - @photo1.reload.pending.should be false - @photo2.reload.pending.should be false + expect(@photo1.reload.pending).to be false + expect(@photo2.reload.pending).to be false end end end diff --git a/spec/controllers/streams_controller_spec.rb b/spec/controllers/streams_controller_spec.rb index e6735f4a578d9b13f330f94068b9f442777de15f..05440948f052af0f6e2a2f33a0cf71c2baeb30bc 100644 --- a/spec/controllers/streams_controller_spec.rb +++ b/spec/controllers/streams_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe StreamsController do +describe StreamsController, :type => :controller do before do sign_in alice end @@ -13,24 +13,24 @@ describe StreamsController do it 'will succeed if admin' do Role.add_admin(alice.person) get :public - response.should be_success + expect(response).to be_success end it 'will redirect if not' do get :public - response.should be_redirect + expect(response).to be_redirect end end describe '#multi' do it 'succeeds' do get :multi - response.should be_success + expect(response).to be_success end it 'succeeds on mobile' do get :multi, :format => :mobile - response.should be_success + expect(response).to be_success end end @@ -45,8 +45,8 @@ describe StreamsController do describe "a GET to #{stream_path}" do it 'assigns a stream of the proper class' do get stream_path - response.should be_success - assigns[:stream].should be_a stream_class + expect(response).to be_success + expect(assigns[:stream]).to be_a stream_class end end end diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 25c107b63a643606d57c6062abbabfb5d2d65554..441d630e1da3d9cecc8edbc7a43a115faaffbb1b 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe TagsController do +describe TagsController, :type => :controller do describe '#index (search)' do before do sign_in :user, alice @@ -16,22 +16,22 @@ describe TagsController do it 'responds with json' do get :index, :q => "ra", :format => 'json' #parse json - response.body.should include("#rad") + expect(response.body).to include("#rad") end it 'requires at least two characters' do get :index, :q => "c", :format => 'json' - response.body.should_not include("#cats") + expect(response.body).not_to include("#cats") end it 'redirects the aimless to excellent parties' do get :index - response.should redirect_to tag_path('partytimeexcellent') + expect(response).to redirect_to tag_path('partytimeexcellent') end it 'does not allow json requestors to party' do get :index, :format => :json - response.status.should == 422 + expect(response.status).to eq(422) end end @@ -43,7 +43,7 @@ describe TagsController do it 'redirect to the downcase tag uri' do get :show, :name => 'DiasporaRocks!' - response.should redirect_to(:action => :show, :name => 'diasporarocks!') + expect(response).to redirect_to(:action => :show, :name => 'diasporarocks!') end end @@ -54,29 +54,29 @@ describe TagsController do it 'assigns a Stream::Tag object with the current_user' do get :show, :name => 'yes' - assigns[:stream].user.should == alice + expect(assigns[:stream].user).to eq(alice) end it 'succeeds' do get :show, :name => 'hellyes' - response.status.should == 200 + expect(response.status).to eq(200) end end context "not signed in" do it 'assigns a Stream::Tag object with no user' do get :show, :name => 'yes' - assigns[:stream].user.should be_nil + expect(assigns[:stream].user).to be_nil end it 'succeeds' do get :show, :name => 'hellyes' - response.status.should == 200 + expect(response.status).to eq(200) end it 'succeeds with mobile' do get :show, :name => 'foo', :format => :mobile - response.should be_success + expect(response).to be_success end end end @@ -86,17 +86,17 @@ describe TagsController do before do sign_in bob @tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent") - @controller.stub(:current_user).and_return(bob) - @controller.stub(:params).and_return({:name => "PARTYTIMEexcellent"}) + allow(@controller).to receive(:current_user).and_return(bob) + allow(@controller).to receive(:params).and_return({:name => "PARTYTIMEexcellent"}) end it 'returns true if the following already exists and should be case insensitive' do TagFollowing.create!(:tag => @tag, :user => bob ) - @controller.send(:tag_followed?).should be true + expect(@controller.send(:tag_followed?)).to be true end it 'returns false if the following does not already exist' do - @controller.send(:tag_followed?).should be false + expect(@controller.send(:tag_followed?)).to be false end end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index ad24ece054ee372ce1de75d5af3ed31f9753e454..fb53282e0a9d21e26c00a03c22058dacf8e83ad8 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -4,36 +4,36 @@ require 'spec_helper' -describe UsersController do +describe UsersController, :type => :controller do before do @user = alice sign_in :user, @user - @controller.stub(:current_user).and_return(@user) + allow(@controller).to receive(:current_user).and_return(@user) end describe '#export' do it 'returns an xml file' do get :export - response.header["Content-Type"].should include "application/xml" + expect(response.header["Content-Type"]).to include "application/xml" end end describe '#export_photos' do it 'returns a tar file' do get :export_photos - response.header["Content-Type"].should include "application/octet-stream" + expect(response.header["Content-Type"]).to include "application/octet-stream" end end describe 'user_photo' do it 'should return the url of the users profile photo' do get :user_photo, :username => @user.username - response.should redirect_to(@user.profile.image_url) + expect(response).to redirect_to(@user.profile.image_url) end it 'should 404 if no user is found' do get :user_photo, :username => 'none' - response.should_not be_success + expect(response).not_to be_success end end @@ -41,7 +41,7 @@ describe UsersController do it 'renders xml if atom is requested' do sm = FactoryGirl.create(:status_message, :public => true, :author => @user.person) get :public, :username => @user.username, :format => :atom - response.body.should include(sm.raw_message) + expect(response.body).to include(sm.raw_message) end it 'renders xml if atom is requested with clickalbe urls' do @@ -51,13 +51,13 @@ describe UsersController do p.save end get :public, :username => @user.username, :format => :atom - response.body.should include('a href') + expect(response.body).to include('a href') end it 'includes reshares in the atom feed' do reshare = FactoryGirl.create(:reshare, :author => @user.person) get :public, :username => @user.username, :format => :atom - response.body.should include reshare.root.raw_message + expect(response.body).to include reshare.root.raw_message end it 'do not show reshares in atom feed if origin post is deleted' do @@ -65,17 +65,17 @@ describe UsersController do reshare = FactoryGirl.create(:reshare, :root => post, :author => @user.person) post.delete get :public, :username => @user.username, :format => :atom - response.code.should == '200' + expect(response.code).to eq('200') end it 'redirects to a profile page if html is requested' do get :public, :username => @user.username - response.should be_redirect + expect(response).to be_redirect end it 'redirects to a profile page if mobile is requested' do get :public, :username => @user.username, :format => :mobile - response.should be_redirect + expect(response).to be_redirect end end @@ -86,19 +86,19 @@ describe UsersController do end it "doesn't overwrite random attributes" do - lambda { + expect { put :update, @params - }.should_not change(@user, :diaspora_handle) + }.not_to change(@user, :diaspora_handle) end it 'redirects to the user edit page' do put :update, @params - response.should redirect_to edit_user_path + expect(response).to redirect_to edit_user_path end it 'responds with a 204 on a js request' do put :update, @params.merge(:format => :js) - response.status.should == 204 + expect(response.status).to eq(204) end context 'password updates' do @@ -109,8 +109,8 @@ describe UsersController do end it "uses devise's update with password" do - @user.should_receive(:update_with_password).with(hash_including(@password_params)) - @controller.stub(:current_user).and_return(@user) + expect(@user).to receive(:update_with_password).with(hash_including(@password_params)) + allow(@controller).to receive(:current_user).and_return(@user) put :update, :id => @user.id, :user => @password_params end end @@ -124,7 +124,7 @@ describe UsersController do { :language => "fr"} ) @user.reload - @user.language.should_not == old_language + expect(@user.language).not_to eq(old_language) end end @@ -133,35 +133,35 @@ describe UsersController do @user.email = "my@newemail.com" put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) @user.reload - @user.unconfirmed_email.should eql(nil) + expect(@user.unconfirmed_email).to eql(nil) end it 'allow the user to change his (unconfirmed) email' do put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) @user.reload - @user.unconfirmed_email.should eql("my@newemail.com") + expect(@user.unconfirmed_email).to eql("my@newemail.com") end it 'informs the user about success' do put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) - request.flash[:notice].should eql(I18n.t('users.update.unconfirmed_email_changed')) - request.flash[:error].should be_blank + expect(request.flash[:notice]).to eql(I18n.t('users.update.unconfirmed_email_changed')) + expect(request.flash[:error]).to be_blank end it 'informs the user about failure' do put(:update, :id => @user.id, :user => { :email => "my@newemailcom"}) - request.flash[:error].should eql(I18n.t('users.update.unconfirmed_email_not_changed')) - request.flash[:notice].should be_blank + expect(request.flash[:error]).to eql(I18n.t('users.update.unconfirmed_email_not_changed')) + expect(request.flash[:notice]).to be_blank end it 'allow the user to change his (unconfirmed) email to blank (= abort confirmation)' do put(:update, :id => @user.id, :user => { :email => ""}) @user.reload - @user.unconfirmed_email.should eql(nil) + expect(@user.unconfirmed_email).to eql(nil) end it 'sends out activation email on success' do - Workers::Mail::ConfirmEmail.should_receive(:perform_async).with(@user.id).once + expect(Workers::Mail::ConfirmEmail).to receive(:perform_async).with(@user.id).once put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) end end @@ -169,24 +169,24 @@ describe UsersController do describe 'email settings' do it 'lets the user turn off mail' do par = {:id => @user.id, :user => {:email_preferences => {'mentioned' => 'true'}}} - proc{ + expect{ put :update, par - }.should change(@user.user_preferences, :count).by(1) + }.to change(@user.user_preferences, :count).by(1) end it 'lets the user get mail again' do @user.user_preferences.create(:email_type => 'mentioned') par = {:id => @user.id, :user => {:email_preferences => {'mentioned' => 'false'}}} - proc{ + expect{ put :update, par - }.should change(@user.user_preferences, :count).by(-1) + }.to change(@user.user_preferences, :count).by(-1) end end describe 'getting started' do it 'can be reenabled' do put :update, user: {getting_started: true} - @user.reload.getting_started?.should be true + expect(@user.reload.getting_started?).to be true end end end @@ -194,43 +194,43 @@ describe UsersController do describe '#privacy_settings' do it "returns a 200" do get 'privacy_settings' - response.status.should == 200 + expect(response.status).to eq(200) end end describe '#edit' do it "returns a 200" do get 'edit', :id => @user.id - response.status.should == 200 + expect(response.status).to eq(200) end it 'set @email_pref to false when there is a user pref' do @user.user_preferences.create(:email_type => 'mentioned') get 'edit', :id => @user.id - assigns[:email_prefs]['mentioned'].should be false + expect(assigns[:email_prefs]['mentioned']).to be false end it 'does not allow token auth' do sign_out :user bob.reset_authentication_token! get :edit, :auth_token => bob.authentication_token - response.should redirect_to new_user_session_path + expect(response).to redirect_to new_user_session_path end end describe '#destroy' do it 'does nothing if the password does not match' do - Workers::DeleteAccount.should_not_receive(:perform_async) + expect(Workers::DeleteAccount).not_to receive(:perform_async) delete :destroy, :user => { :current_password => "stuff" } end it 'closes the account' do - alice.should_receive(:close_account!) + expect(alice).to receive(:close_account!) delete :destroy, :user => { :current_password => "bluepin7" } end it 'enqueues a delete job' do - Workers::DeleteAccount.should_receive(:perform_async).with(anything) + expect(Workers::DeleteAccount).to receive(:perform_async).with(anything) delete :destroy, :user => { :current_password => "bluepin7" } end end @@ -242,35 +242,35 @@ describe UsersController do it 'redirects to to the user edit page' do get 'confirm_email', :token => @user.confirm_email_token - response.should redirect_to edit_user_path + expect(response).to redirect_to edit_user_path end it 'confirms email' do get 'confirm_email', :token => @user.confirm_email_token @user.reload - @user.email.should eql('my@newemail.com') - request.flash[:notice].should eql(I18n.t('users.confirm_email.email_confirmed', :email => 'my@newemail.com')) - request.flash[:error].should be_blank + expect(@user.email).to eql('my@newemail.com') + expect(request.flash[:notice]).to eql(I18n.t('users.confirm_email.email_confirmed', :email => 'my@newemail.com')) + expect(request.flash[:error]).to be_blank end it 'does NOT confirm email with wrong token' do get 'confirm_email', :token => @user.confirm_email_token.reverse @user.reload - @user.email.should_not eql('my@newemail.com') - request.flash[:error].should eql(I18n.t('users.confirm_email.email_not_confirmed')) - request.flash[:notice].should be_blank + expect(@user.email).not_to eql('my@newemail.com') + expect(request.flash[:error]).to eql(I18n.t('users.confirm_email.email_not_confirmed')) + expect(request.flash[:notice]).to be_blank end end describe 'getting_started' do it 'does not fail miserably' do get :getting_started - response.should be_success + expect(response).to be_success end it 'does not fail miserably on mobile' do get :getting_started, :format => :mobile - response.should be_success + expect(response).to be_success end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 043fe0b228d872647394c81e448e7a5b1b689e4b..b75db953329f9b2343129266d313cb16de5c2081 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ApplicationHelper do +describe ApplicationHelper, :type => :helper do before do @user = alice @person = FactoryGirl.create(:person) @@ -19,12 +19,12 @@ describe ApplicationHelper do it 'links to community spotlight' do @current_user = FactoryGirl.create(:user) - contacts_link.should == community_spotlight_path + expect(contacts_link).to eq(community_spotlight_path) end it 'links to contacts#index' do @current_user = alice - contacts_link.should == contacts_path + expect(contacts_link).to eq(contacts_path) end end @@ -45,12 +45,12 @@ describe ApplicationHelper do it 'returns true if all networks are connected' do 3.times { |t| @current_user.services << FactoryGirl.build(:service) } - all_services_connected?.should be true + expect(all_services_connected?).to be true end it 'returns false if not all networks are connected' do @current_user.services.delete_all - all_services_connected?.should be false + expect(all_services_connected?).to be false end end @@ -61,11 +61,11 @@ describe ApplicationHelper do end it 'inclues jquery.js from jquery cdn' do - jquery_include_tag.should match(/jquery\.com/) + expect(jquery_include_tag).to match(/jquery\.com/) end it 'falls back to asset pipeline on cdn failure' do - jquery_include_tag.should match(/document\.write/) + expect(jquery_include_tag).to match(/document\.write/) end end @@ -75,17 +75,17 @@ describe ApplicationHelper do end it 'includes jquery.js from asset pipeline' do - jquery_include_tag.should match(/jquery\.js/) - jquery_include_tag.should_not match(/jquery\.com/) + expect(jquery_include_tag).to match(/jquery\.js/) + expect(jquery_include_tag).not_to match(/jquery\.com/) end end it 'inclues jquery_ujs.js' do - jquery_include_tag.should match(/jquery_ujs\.js/) + expect(jquery_include_tag).to match(/jquery_ujs\.js/) end it "disables ajax caching" do - jquery_include_tag.should match(/jQuery\.ajaxSetup/) + expect(jquery_include_tag).to match(/jQuery\.ajaxSetup/) end end @@ -93,14 +93,14 @@ describe ApplicationHelper do it 'defaults to master branch changleog' do old_revision = AppConfig.git_revision AppConfig.git_revision = nil - changelog_url.should == 'https://github.com/diaspora/diaspora/blob/master/Changelog.md' + expect(changelog_url).to eq('https://github.com/diaspora/diaspora/blob/master/Changelog.md') AppConfig.git_revision = old_revision end it 'displays the changelog for the current git revision if set' do old_revision = AppConfig.git_revision AppConfig.git_revision = '123' - changelog_url.should == 'https://github.com/diaspora/diaspora/blob/123/Changelog.md' + expect(changelog_url).to eq('https://github.com/diaspora/diaspora/blob/123/Changelog.md') AppConfig.git_revision = old_revision end @@ -108,13 +108,13 @@ describe ApplicationHelper do describe '#pod_name' do it 'defaults to Diaspora*' do - pod_name.should match /DIASPORA/i + expect(pod_name).to match /DIASPORA/i end it 'displays the supplied pod_name if it is set' do old_name = AppConfig.settings.pod_name.get AppConfig.settings.pod_name = "Catspora" - pod_name.should match "Catspora" + expect(pod_name).to match "Catspora" AppConfig.settings.pod_name = old_name end end @@ -124,7 +124,7 @@ describe ApplicationHelper do it 'displays the supplied pod_version if it is set' do old_version = AppConfig.version.number.get AppConfig.version.number = "0.0.1.0" - pod_version.should match "0.0.1.0" + expect(pod_version).to match "0.0.1.0" AppConfig.version.number = old_version end end diff --git a/spec/helpers/getting_started_helper_spec.rb b/spec/helpers/getting_started_helper_spec.rb index 731b38af8431b4f6fb8a438e3b68d92d0ddbb4f8..fea1fcf89956220681aec6cb966baf931fdc8f9f 100644 --- a/spec/helpers/getting_started_helper_spec.rb +++ b/spec/helpers/getting_started_helper_spec.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. require 'spec_helper' -describe GettingStartedHelper do +describe GettingStartedHelper, :type => :helper do before do @current_user = alice end @@ -16,13 +16,13 @@ describe GettingStartedHelper do it 'returns true if the current user has completed getting started' do @current_user.getting_started = false @current_user.save - has_completed_getting_started?.should be true + expect(has_completed_getting_started?).to be true end it 'returns false if the current user has not completed getting started' do @current_user.getting_started = true @current_user.save - has_completed_getting_started?.should be false + expect(has_completed_getting_started?).to be false end end end diff --git a/spec/helpers/interim_stream_hackiness_helper_spec.rb b/spec/helpers/interim_stream_hackiness_helper_spec.rb index 2212976f429f514675a8fc912aca78a19b789489..c0cbb0ba576297f76c0b5c74e30f42dd35988bf7 100644 --- a/spec/helpers/interim_stream_hackiness_helper_spec.rb +++ b/spec/helpers/interim_stream_hackiness_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe InterimStreamHackinessHelper do +describe InterimStreamHackinessHelper, :type => :helper do describe 'commenting_disabled?' do include Devise::TestHelpers before do @@ -14,24 +14,24 @@ describe InterimStreamHackinessHelper do def user_signed_in? false end - commenting_disabled?(double).should == true + expect(commenting_disabled?(double)).to eq(true) end it 'returns true if @commenting_disabled is set' do @commenting_disabled = true - commenting_disabled?(double).should == true + expect(commenting_disabled?(double)).to eq(true) @commenting_disabled = false - commenting_disabled?(double).should == false + expect(commenting_disabled?(double)).to eq(false) end it 'returns @stream.can_comment? if @stream is set' do post = double @stream = double - @stream.should_receive(:can_comment?).with(post).and_return(true) - commenting_disabled?(post).should == false + expect(@stream).to receive(:can_comment?).with(post).and_return(true) + expect(commenting_disabled?(post)).to eq(false) - @stream.should_receive(:can_comment?).with(post).and_return(false) - commenting_disabled?(post).should == true + expect(@stream).to receive(:can_comment?).with(post).and_return(false) + expect(commenting_disabled?(post)).to eq(true) end end end diff --git a/spec/helpers/invitation_codes_helper_spec.rb b/spec/helpers/invitation_codes_helper_spec.rb index 56010b81cae351ee08df9a4f863af1e6a93dc675..5ebd8b1ef90e3f06893df82a59179d7fb84e16fc 100644 --- a/spec/helpers/invitation_codes_helper_spec.rb +++ b/spec/helpers/invitation_codes_helper_spec.rb @@ -10,6 +10,6 @@ require 'spec_helper' # end # end # end -describe InvitationCodesHelper do +describe InvitationCodesHelper, :type => :helper do skip "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/helpers/layout_helper_spec.rb b/spec/helpers/layout_helper_spec.rb index 33b3ae2e1879f05756afcb671790776513f50f5e..8810e9ee337b060e81f05dc8b1ce3398ec762b61 100644 --- a/spec/helpers/layout_helper_spec.rb +++ b/spec/helpers/layout_helper_spec.rb @@ -4,18 +4,18 @@ require 'spec_helper' -describe LayoutHelper do +describe LayoutHelper, :type => :helper do describe "#page_title" do context "passed blank text" do it "returns Diaspora*" do - page_title.to_s.should == pod_name + expect(page_title.to_s).to eq(pod_name) end end context "passed text" do it "returns the text" do text = "This is the title" - page_title(text).should == text + expect(page_title(text)).to eq(text) end end end diff --git a/spec/helpers/mobile_helper_spec.rb b/spec/helpers/mobile_helper_spec.rb index 18a870bdf27604e0bf324861c2c38e9e96636f9b..c506b3b3ce6fdafc18bb8af09280e6908ba459a8 100644 --- a/spec/helpers/mobile_helper_spec.rb +++ b/spec/helpers/mobile_helper_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe MobileHelper do +describe MobileHelper, :type => :helper do describe "#aspect_select_options" do it "adds an all option to the list of aspects" do @@ -13,7 +13,7 @@ describe MobileHelper do n = FactoryGirl.create(:aspect) options = aspect_select_options([n], n).split('\n') - options.first.should =~ /All/ + expect(options.first).to match(/All/) end end end \ No newline at end of file diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index 94817dd0ac02ef9a8e0c64a4cad0ab8503cf4e39..2e30be97683ae34d033128d2c7bbc101b870acf7 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe NotificationsHelper do +describe NotificationsHelper, :type => :helper do include ApplicationHelper before do @@ -38,28 +38,28 @@ describe NotificationsHelper do end it 'with two, does not comma seperate two actors' do - @note.stub(:actors).and_return([@max, @sarah]) - output.scan(/,/).should be_empty - output.scan(/and/).count.should be 1 + allow(@note).to receive(:actors).and_return([@max, @sarah]) + expect(output.scan(/,/)).to be_empty + expect(output.scan(/and/).count).to be 1 end it 'with three, comma seperates the first two, and and the last actor' do - @note.stub(:actors).and_return([@max, @sarah, @daniel]) - output.scan(/,/).count.should be 2 - output.scan(/and/).count.should be 1 + allow(@note).to receive(:actors).and_return([@max, @sarah, @daniel]) + expect(output.scan(/,/).count).to be 2 + expect(output.scan(/and/).count).to be 1 end it 'with more than three, lists the first three, then the others tag' do - @note.stub(:actors).and_return([@max, @sarah, @daniel, @ilya]) - output.scan(/,/).count.should be 3 - output.scan(/and/).count.should be 2 + allow(@note).to receive(:actors).and_return([@max, @sarah, @daniel, @ilya]) + expect(output.scan(/,/).count).to be 3 + expect(output.scan(/and/).count).to be 2 end end describe 'for a like' do it 'displays #{list of actors}' do output = notification_people_link(@notification) - output.should include @person2.name - output.should include @person.name + expect(output).to include @person2.name + expect(output).to include @person.name end end end @@ -69,12 +69,12 @@ describe NotificationsHelper do describe 'for a like' do it 'should include a link to the post' do output = object_link(@notification, notification_people_link(@notification)) - output.should include post_path(@post) + expect(output).to include post_path(@post) end it 'includes the boilerplate translation' do output = object_link(@notification, notification_people_link(@notification)) - output.should include I18n.t("#{@notification.popup_translation_key}", + expect(output).to include I18n.t("#{@notification.popup_translation_key}", :actors => notification_people_link(@notification), :count => @notification.actors.count, :post_link => link_to(post_page_title(@post), post_path(@post), 'data-ref' => @post.id, :class => 'hard_object_link').html_safe) @@ -88,7 +88,7 @@ describe NotificationsHelper do it 'displays that the post was deleted' do @post.destroy - object_link(@notification, notification_people_link(@notification)).should == t('notifications.liked_post_deleted.one', :actors => notification_people_link(@notification)) + expect(object_link(@notification, notification_people_link(@notification))).to eq(t('notifications.liked_post_deleted.one', :actors => notification_people_link(@notification))) end end end diff --git a/spec/helpers/notifier_helper_spec.rb b/spec/helpers/notifier_helper_spec.rb index 9f3e887e9888043954135630f9c965886f5e6034..542f7a1504ecf530645fe8fd883d6670814ba2c5 100644 --- a/spec/helpers/notifier_helper_spec.rb +++ b/spec/helpers/notifier_helper_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe NotifierHelper do +describe NotifierHelper, :type => :helper do describe '#post_message' do before do # post for truncate test @@ -19,12 +19,12 @@ describe NotifierHelper do it 'truncates in the post' do opts = {:length => @post.text.length - 10} - post_message(@post, opts).should == @truncated_post + expect(post_message(@post, opts)).to eq(@truncated_post) end it 'strip markdown in the post' do opts = {:length => @markdown_post.text.length} - post_message(@markdown_post, opts).should == @striped_markdown_post + expect(post_message(@markdown_post, opts)).to eq(@striped_markdown_post) end end @@ -42,12 +42,12 @@ describe NotifierHelper do it 'truncates in the comment' do opts = {:length => @comment.text.length - 10} - comment_message(@comment, opts).should == @truncated_comment + expect(comment_message(@comment, opts)).to eq(@truncated_comment) end it 'strip markdown in the comment' do opts = {:length => @markdown_comment.text.length} - comment_message(@markdown_comment, opts).should == @striped_markdown_comment + expect(comment_message(@markdown_comment, opts)).to eq(@striped_markdown_comment) end end end diff --git a/spec/helpers/o_embed_helper_spec.rb b/spec/helpers/o_embed_helper_spec.rb index 3668a6783bbc273d65a82be568a66e3b728c6bf9..306860ebf3792d26d42139d56c1e65e99df8a2bf 100644 --- a/spec/helpers/o_embed_helper_spec.rb +++ b/spec/helpers/o_embed_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe OEmbedHelper do +describe OEmbedHelper, :type => :helper do describe 'o_embed_html' do scenarios = { "photo" => { @@ -112,15 +112,15 @@ describe OEmbedHelper do formatted = o_embed_html(cache).gsub('https://', 'http://') case type when 'photo' - formatted.should =~ /#{data['oembed_data']['url']}/ + expect(formatted).to match(/#{data['oembed_data']['url']}/) when 'unsupported' - formatted.should =~ /#{data['link_url']}/ + expect(formatted).to match(/#{data['link_url']}/) when 'secure_video', 'secure_rich' - formatted.should =~ /#{data['oembed_data']['html']}/ + expect(formatted).to match(/#{data['oembed_data']['html']}/) when 'unsecure_video', 'unsecure_rich' - formatted.should_not =~ /#{data['oembed_data']['html']}/ - formatted.should =~ /#{data['oembed_data']['title']}/ - formatted.should =~ /#{data['oembed_data']['url']}/ + expect(formatted).not_to match(/#{data['oembed_data']['html']}/) + expect(formatted).to match(/#{data['oembed_data']['title']}/) + expect(formatted).to match(/#{data['oembed_data']['url']}/) end end end diff --git a/spec/helpers/open_graph_helper_spec.rb b/spec/helpers/open_graph_helper_spec.rb index f6b72f1fa338bfb54110804cabf51fb6ccc97520..2518ee0619316937351944d9ca5737956130b3f9 100644 --- a/spec/helpers/open_graph_helper_spec.rb +++ b/spec/helpers/open_graph_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe OpenGraphHelper do +describe OpenGraphHelper, :type => :helper do describe 'og_html' do scenarios = { "article" => { @@ -21,10 +21,10 @@ describe OpenGraphHelper do formatted = og_html(cache) - formatted.should =~ /#{data['url']}/ - formatted.should =~ /#{data['title']}/ - formatted.should =~ /#{data['image']}/ - formatted.should =~ /#{data['description']}/ + expect(formatted).to match(/#{data['url']}/) + expect(formatted).to match(/#{data['title']}/) + expect(formatted).to match(/#{data['image']}/) + expect(formatted).to match(/#{data['description']}/) end end end diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb index f8ff428138fd02bdc976861f2b2e61fe0e92171b..31976a4b57d95d58fd4649a0ad021c8af6c904ec 100644 --- a/spec/helpers/people_helper_spec.rb +++ b/spec/helpers/people_helper_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PeopleHelper do +describe PeopleHelper, :type => :helper do before do @user = alice @person = FactoryGirl.create(:person) @@ -12,13 +12,13 @@ describe PeopleHelper do describe "#person_image_link" do it "returns an empty string if person is nil" do - person_image_link(nil).should == "" + expect(person_image_link(nil)).to eq("") end it "returns a link containing the person's photo" do - person_image_link(@person).should include(@person.profile.image_url) + expect(person_image_link(@person)).to include(@person.profile.image_url) end it "returns a link to the person's profile" do - person_image_link(@person).should include(person_path(@person)) + expect(person_image_link(@person)).to include(person_path(@person)) end end @@ -26,7 +26,7 @@ describe PeopleHelper do it "should not allow basic XSS/HTML" do @person.profile.first_name = "I'm <h1>Evil" @person.profile.last_name = "I'm <h1>Evil" - person_image_tag(@person).should_not include("<h1>") + expect(person_image_tag(@person)).not_to include("<h1>") end end @@ -36,31 +36,31 @@ describe PeopleHelper do end it 'includes the name of the person if they have a first name' do - person_link(@person).should include @person.profile.first_name + expect(person_link(@person)).to include @person.profile.first_name end it 'uses diaspora handle if the person has no first or last name' do @person.profile.first_name = nil @person.profile.last_name = nil - person_link(@person).should include @person.diaspora_handle + expect(person_link(@person)).to include @person.diaspora_handle end it 'uses diaspora handle if first name and first name are rails#blank?' do @person.profile.first_name = " " @person.profile.last_name = " " - person_link(@person).should include @person.diaspora_handle + expect(person_link(@person)).to include @person.diaspora_handle end it "should not allow basic XSS/HTML" do @person.profile.first_name = "I'm <h1>Evil" @person.profile.last_name = "I'm <h1>Evil" - person_link(@person).should_not include("<h1>") + expect(person_link(@person)).not_to include("<h1>") end it 'links by id for a local user' do - person_link(@user.person).should include "href='#{person_path(@user.person)}'" + expect(person_link(@user.person)).to include "href='#{person_path(@user.person)}'" end end @@ -68,13 +68,13 @@ describe PeopleHelper do it "calls local_or_remote_person_path and passes through the options" do opts = {:absolute => true} - self.should_receive(:local_or_remote_person_path).with(@person, opts).exactly(1).times + expect(self).to receive(:local_or_remote_person_path).with(@person, opts).exactly(1).times person_href(@person, opts) end it "returns a href attribute" do - person_href(@person).should include "href=" + expect(person_href(@person)).to include "href=" end end @@ -85,20 +85,20 @@ describe PeopleHelper do it "links by id if there is a period in the user's username" do @user.username = "invalid.username" - @user.save(:validate => false).should == true + expect(@user.save(:validate => false)).to eq(true) person = @user.person person.diaspora_handle = "#{@user.username}@#{AppConfig.pod_uri.authority}" person.save! - local_or_remote_person_path(@user.person).should == person_path(@user.person) + expect(local_or_remote_person_path(@user.person)).to eq(person_path(@user.person)) end it 'links by username for a local user' do - local_or_remote_person_path(@user.person).should == user_profile_path(:username => @user.username) + expect(local_or_remote_person_path(@user.person)).to eq(user_profile_path(:username => @user.username)) end it 'links by id for a remote person' do - local_or_remote_person_path(@person).should == person_path(@person) + expect(local_or_remote_person_path(@person)).to eq(person_path(@person)) end end @@ -110,16 +110,16 @@ describe PeopleHelper do context 'when the contact is sharing' do it 'shows the sharing message' do message = I18n.t('people.helper.is_sharing', :name => @person.name) - @contact.stub(:sharing?).and_return(true) - sharing_message(@person, @contact).should include(message) + allow(@contact).to receive(:sharing?).and_return(true) + expect(sharing_message(@person, @contact)).to include(message) end end context 'when the contact is not sharing' do it 'does show the not sharing message' do message = I18n.t('people.helper.is_not_sharing', :name => @person.name) - @contact.stub(:sharing?).and_return(false) - sharing_message(@person, @contact).should include(message) + allow(@contact).to receive(:sharing?).and_return(false) + expect(sharing_message(@person, @contact)).to include(message) end end end diff --git a/spec/helpers/posts_helper_spec.rb b/spec/helpers/posts_helper_spec.rb index 1d1d6edee9c68e5ba343f994c1b4c99d1d96ac2c..d1624f8dcb74041296c80040db5b876e175cd159 100644 --- a/spec/helpers/posts_helper_spec.rb +++ b/spec/helpers/posts_helper_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PostsHelper do +describe PostsHelper, :type => :helper do describe '#post_page_title' do before do @@ -14,7 +14,7 @@ describe PostsHelper do context 'with posts with text' do it "delegates to message.title" do message = double - message.should_receive(:title) + expect(message).to receive(:title) post = double(message: message) post_page_title(post) end @@ -28,11 +28,11 @@ describe PostsHelper do end it "returns an iframe tag" do - post_iframe_url(@post.id).should include "iframe" + expect(post_iframe_url(@post.id)).to include "iframe" end it "returns an iframe containing the post" do - post_iframe_url(@post.id).should include "src='http://localhost:9887#{post_path(@post)}'" + expect(post_iframe_url(@post.id)).to include "src='http://localhost:9887#{post_path(@post)}'" end end end diff --git a/spec/helpers/stream_helper_spec.rb b/spec/helpers/stream_helper_spec.rb index b44b54d1c430591ae353bf8e4cdc7b75c6821005..b7c39ce100f282947e156d5d053c06e9ea72d6fd 100644 --- a/spec/helpers/stream_helper_spec.rb +++ b/spec/helpers/stream_helper_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe StreamHelper do +describe StreamHelper, :type => :helper do describe "next_page_path" do def build_controller controller_class controller_class.new.tap {|c| c.request = controller.request } @@ -14,29 +14,29 @@ describe StreamHelper do end it 'works for public page' do - helper.stub(:controller).and_return(build_controller(PostsController)) - helper.next_page_path.should include '/public' + allow(helper).to receive(:controller).and_return(build_controller(PostsController)) + expect(helper.next_page_path).to include '/public' end it 'works for stream page when current page is stream' do - helper.stub(:current_page?).and_return(false) - helper.should_receive(:current_page?).with(:stream).and_return(true) - helper.stub(:controller).and_return(build_controller(StreamsController)) - helper.next_page_path.should include stream_path + allow(helper).to receive(:current_page?).and_return(false) + expect(helper).to receive(:current_page?).with(:stream).and_return(true) + allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) + expect(helper.next_page_path).to include stream_path end it 'works for aspects page when current page is aspects' do - helper.stub(:current_page?).and_return(false) - helper.should_receive(:current_page?).with(:aspects_stream).and_return(true) - helper.stub(:controller).and_return(build_controller(StreamsController)) - helper.next_page_path.should include aspects_stream_path + allow(helper).to receive(:current_page?).and_return(false) + expect(helper).to receive(:current_page?).with(:aspects_stream).and_return(true) + allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) + expect(helper.next_page_path).to include aspects_stream_path end it 'works for activity page when current page is not stream or aspects' do - helper.stub(:current_page?).and_return(false) - helper.stub(:controller).and_return(build_controller(StreamsController)) + allow(helper).to receive(:current_page?).and_return(false) + allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) # binding.pry - helper.next_page_path.should include activity_stream_path + expect(helper.next_page_path).to include activity_stream_path end end end diff --git a/spec/helpers/tags_helper_spec.rb b/spec/helpers/tags_helper_spec.rb index f62edef904c208569a1a75ad78e48a9e464d3aca..e48990a827bb2ceffb64644a4e7d52b567a5b051 100644 --- a/spec/helpers/tags_helper_spec.rb +++ b/spec/helpers/tags_helper_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' -describe TagsHelper do +describe TagsHelper, :type => :helper do describe '#looking_for_tag_link' do it 'returns nil if there is a @ in the query' do - helper.stub(:search_query).and_return('foo@bar.com') - helper.looking_for_tag_link.should be_nil + allow(helper).to receive(:search_query).and_return('foo@bar.com') + expect(helper.looking_for_tag_link).to be_nil end it 'returns nil if it normalizes to blank' do - helper.stub(:search_query).and_return('++') - helper.looking_for_tag_link.should be_nil + allow(helper).to receive(:search_query).and_return('++') + expect(helper.looking_for_tag_link).to be_nil end it 'returns a link to the tag otherwise' do - helper.stub(:search_query).and_return('foo') - helper.looking_for_tag_link.should include(helper.tag_link) + allow(helper).to receive(:search_query).and_return('foo') + expect(helper.looking_for_tag_link).to include(helper.tag_link) end end end diff --git a/spec/integration/account_deletion_spec.rb b/spec/integration/account_deletion_spec.rb index babc748f88a5c6da6ddd1b7f3c06df8b5c6c413c..71e52786e93a406317bd751d692e3a6d7d05bacb 100644 --- a/spec/integration/account_deletion_spec.rb +++ b/spec/integration/account_deletion_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'deleteing your account' do +describe 'deleteing your account', :type => :request do context "user" do before do @bob2 = bob @@ -54,42 +54,42 @@ describe 'deleteing your account' do end it "deletes all of the user's preferences" do - UserPreference.where(:id => @prefs.map{|pref| pref.id}).should be_empty + expect(UserPreference.where(:id => @prefs.map{|pref| pref.id})).to be_empty end it "deletes all of the user's notifications" do - Notification.where(:id => @notifications.map{|n| n.id}).should be_empty + expect(Notification.where(:id => @notifications.map{|n| n.id})).to be_empty end it "deletes all of the users's blocked users" do - Block.where(:id => @block.id).should be_empty + expect(Block.where(:id => @block.id)).to be_empty end it "deletes all of the user's services" do - Service.where(:id => @services.map{|s| s.id}).should be_empty + expect(Service.where(:id => @services.map{|s| s.id})).to be_empty end it 'deletes all of @bob2s share visiblites' do - ShareVisibility.where(:id => @users_sv.map{|sv| sv.id}).should be_empty - ShareVisibility.where(:id => @persons_sv.map{|sv| sv.id}).should be_empty + expect(ShareVisibility.where(:id => @users_sv.map{|sv| sv.id})).to be_empty + expect(ShareVisibility.where(:id => @persons_sv.map{|sv| sv.id})).to be_empty end it 'deletes all of @bob2s aspect visiblites' do - AspectVisibility.where(:id => @aspect_vis.map(&:id)).should be_empty + expect(AspectVisibility.where(:id => @aspect_vis.map(&:id))).to be_empty end it 'deletes all aspects' do - @bob2.aspects.should be_empty + expect(@bob2.aspects).to be_empty end it 'deletes all user contacts' do - @bob2.contacts.should be_empty + expect(@bob2.contacts).to be_empty end it "clears the account fields" do @bob2.send(:clearable_fields).each do |field| - @bob2.reload[field].should be_blank + expect(@bob2.reload[field]).to be_blank end end diff --git a/spec/integration/attack_vectors_spec.rb b/spec/integration/attack_vectors_spec.rb index 8683d866a8ba25ea4f895b6e773547a1db8fc766..284823f4ef60e1161adc783ea90baf8a26bf0620 100644 --- a/spec/integration/attack_vectors_spec.rb +++ b/spec/integration/attack_vectors_spec.rb @@ -39,7 +39,7 @@ def expect_error(partial_message, &block)# DOES NOT REQUIRE ERROR!! begin yield rescue => e - e.message.should match partial_message + expect(e.message).to match partial_message ensure raise "no error occured where expected" unless e.present? @@ -53,7 +53,7 @@ def bogus_retraction(&block) end def user_should_not_see_guid(user, guid) - user.reload.visible_shareables(Post).where(:guid => guid).should be_blank + expect(user.reload.visible_shareables(Post).where(:guid => guid)).to be_blank end #returns the message def legit_post_from_user1_to_user2(user1, user2) @@ -62,7 +62,7 @@ def legit_post_from_user1_to_user2(user1, user2) original_message end -describe "attack vectors" do +describe "attack vectors", :type => :request do let(:eves_aspect) { eve.aspects.find_by_name("generic") } let(:alices_aspect) { alice.aspects.find_by_name("generic") } diff --git a/spec/integration/contact_deleting_spec.rb b/spec/integration/contact_deleting_spec.rb index a1c83fd72909237e8fc8bd63c96c3276a9ef59f7..255680d081a5fc6963d0913ed371ca3fefae39a8 100644 --- a/spec/integration/contact_deleting_spec.rb +++ b/spec/integration/contact_deleting_spec.rb @@ -4,13 +4,13 @@ require 'spec_helper' -describe 'disconnecting a contact' do +describe 'disconnecting a contact', :type => :request do it 'removes the aspect membership' do @user = alice @user2 = bob - lambda{ + expect{ @user.disconnect(@user.contact_for(@user2.person)) - }.should change(AspectMembership, :count).by(-1) + }.to change(AspectMembership, :count).by(-1) end end diff --git a/spec/integration/dispatching_spec.rb b/spec/integration/dispatching_spec.rb index af967a66c087ce08122f54cb22ac88fcd9d2c19f..83d4f0e3226af71575b8b59ecca43a1dc1a8b67c 100644 --- a/spec/integration/dispatching_spec.rb +++ b/spec/integration/dispatching_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "Dispatching" do +describe "Dispatching", :type => :request do context "a comment retraction on a public post" do it "should trigger a private dispatch" do luke, leia, raph = set_up_friends @@ -11,8 +11,8 @@ describe "Dispatching" do inlined_jobs do # Luke now retracts his comment - Postzord::Dispatcher::Public.should_not_receive(:new) - Postzord::Dispatcher::Private.should_receive(:new).and_return(double(:post => true)) + expect(Postzord::Dispatcher::Public).not_to receive(:new) + expect(Postzord::Dispatcher::Private).to receive(:new).and_return(double(:post => true)) luke.retract(comment) end end diff --git a/spec/integration/mentioning_spec.rb b/spec/integration/mentioning_spec.rb index aab37d79f17889eb2f3fcd441b8e5a7b5f9ea4ae..d8e851660823644c14b4a8ca91d8083bd12d45e8 100644 --- a/spec/integration/mentioning_spec.rb +++ b/spec/integration/mentioning_spec.rb @@ -26,7 +26,7 @@ module MentioningSpecHelpers end -describe 'mentioning' do +describe 'mentioning', :type => :request do include MentioningSpecHelpers before do @@ -39,20 +39,20 @@ describe 'mentioning' do # see: https://github.com/diaspora/diaspora/issues/4160 it 'only mentions people that are in the target aspect' do - users_connected?(@user1, @user2).should be true - users_connected?(@user1, @user3).should be false + expect(users_connected?(@user1, @user2)).to be true + expect(users_connected?(@user1, @user3)).to be false status_msg = nil - lambda do + expect do status_msg = @user1.post(:status_message, {text: text_mentioning(@user3), to: default_aspect}) - end.should change(Post, :count).by(1) + end.to change(Post, :count).by(1) - status_msg.should_not be_nil - status_msg.public?.should be false - status_msg.text.should include(@user3.name) + expect(status_msg).not_to be_nil + expect(status_msg.public?).to be false + expect(status_msg.text).to include(@user3.name) - notifications_about_mentioning(@user3).should be_empty - stream_for(@user3).map { |item| item.id }.should_not include(status_msg.id) + expect(notifications_about_mentioning(@user3)).to be_empty + expect(stream_for(@user3).map { |item| item.id }).not_to include(status_msg.id) end end diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 99060afafe9ced559c984c0b6da7bcd1a700cc1a..1d31116e91cccbb5b204cfc307c79bf7313b4411 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe 'a user receives a post' do +describe 'a user receives a post', :type => :request do def receive_with_zord(user, person, xml) zord = Postzord::Receiver::Private.new(user, :person => person) @@ -26,9 +26,9 @@ describe 'a user receives a post' do bob.delete status_message.destroy - lambda { + expect { receive_with_zord(alice, bob.person, xml) - }.should change(Post,:count).by(1) + }.to change(Post,:count).by(1) end it 'should not create new aspects on message receive' do @@ -38,7 +38,7 @@ describe 'a user receives a post' do status_message = bob.post :status_message, :text => "store this #{n}!", :to => @bobs_aspect.id end - alice.aspects.size.should == num_aspects + expect(alice.aspects.size).to eq(num_aspects) end it "should show bob's post to alice" do @@ -51,13 +51,13 @@ describe 'a user receives a post' do bob.dispatch_post(sm, :to => @bobs_aspect) end - alice.visible_shareables(Post).count(:all).should == 1 + expect(alice.visible_shareables(Post).count(:all)).to eq(1) end context 'with mentions, ' do it 'adds the notifications for the mentioned users regardless of the order they are received' do - Notification.should_receive(:notify).with(alice, anything(), bob.person) - Notification.should_receive(:notify).with(eve, anything(), bob.person) + expect(Notification).to receive(:notify).with(alice, anything(), bob.person) + expect(Notification).to receive(:notify).with(eve, anything(), bob.person) @sm = bob.build_post(:status_message, :text => "@{#{alice.name}; #{alice.diaspora_handle}} stuff @{#{eve.name}; #{eve.diaspora_handle}}") bob.add_to_streams(@sm, [bob.aspects.first]) @@ -74,7 +74,7 @@ describe 'a user receives a post' do @remote_person = FactoryGirl.create(:person, :diaspora_handle => "foobar@foobar.com") Contact.create!(:user => alice, :person => @remote_person, :aspects => [@alices_aspect]) - Notification.should_receive(:notify).with(alice, anything(), @remote_person) + expect(Notification).to receive(:notify).with(alice, anything(), @remote_person) @sm = FactoryGirl.create(:status_message, :text => "hello @{#{alice.name}; #{alice.diaspora_handle}}", :diaspora_handle => @remote_person.diaspora_handle, :author => @remote_person) @sm.save @@ -84,7 +84,7 @@ describe 'a user receives a post' do end it 'does not notify the mentioned user if the mentioned user is not friends with the post author' do - Notification.should_not_receive(:notify).with(alice, anything(), eve.person) + expect(Notification).not_to receive(:notify).with(alice, anything(), eve.person) @sm = eve.build_post(:status_message, :text => "should not notify @{#{alice.name}; #{alice.diaspora_handle}}") eve.add_to_streams(@sm, [eve.aspects.first]) @@ -103,7 +103,7 @@ describe 'a user receives a post' do receive_with_zord(bob, alice.person, xml) - status.reload.text.should == 'store this!' + expect(status.reload.text).to eq('store this!') end it 'updates posts marked as mutable' do @@ -114,7 +114,7 @@ describe 'a user receives a post' do receive_with_zord(bob, alice.person, xml) - photo.reload.text.should match(/foo/) + expect(photo.reload.text).to match(/foo/) end end @@ -127,7 +127,7 @@ describe 'a user receives a post' do p.tag_string = "#big #rafi #style" p.receive(luke, raph) - p.tags(true).count.should == 3 + expect(p.tags(true).count).to eq(3) end end @@ -140,14 +140,14 @@ describe 'a user receives a post' do end it "adds a received post to the the contact" do - alice.visible_shareables(Post).should include(@status_message) - @contact.posts.should include(@status_message) + expect(alice.visible_shareables(Post)).to include(@status_message) + expect(@contact.posts).to include(@status_message) end it 'removes posts upon forceful removal' do alice.remove_contact(@contact, :force => true) alice.reload - alice.visible_shareables(Post).should_not include @status_message + expect(alice.visible_shareables(Post)).not_to include @status_message end context 'dependent delete' do @@ -156,16 +156,16 @@ describe 'a user receives a post' do alice.contacts.create(:person => @person, :aspects => [@alices_aspect]) @post = FactoryGirl.create(:status_message, :author => @person) - @post.share_visibilities.should be_empty + expect(@post.share_visibilities).to be_empty receive_with_zord(alice, @person, @post.to_diaspora_xml) @contact = alice.contact_for(@person) @contact.share_visibilities.reset - @contact.posts(true).should include(@post) + expect(@contact.posts(true)).to include(@post) @post.share_visibilities.reset - lambda { + expect { alice.disconnected_by(@person) - }.should change{@post.share_visibilities(true).count}.by(-1) + }.to change{@post.share_visibilities(true).count}.by(-1) end end end @@ -200,21 +200,21 @@ describe 'a user receives a post' do end it 'should receive a relayed comment with leading whitespace' do - eve.reload.visible_shareables(Post).size.should == 1 + expect(eve.reload.visible_shareables(Post).size).to eq(1) post_in_db = StatusMessage.find(@post.id) - post_in_db.comments.should == [] + expect(post_in_db.comments).to eq([]) receive_with_zord(eve, alice.person, @xml_with_whitespace) - post_in_db.comments(true).first.guid.should == @guid_with_whitespace + expect(post_in_db.comments(true).first.guid).to eq(@guid_with_whitespace) end it 'should correctly attach the user already on the pod' do - bob.reload.visible_shareables(Post).size.should == 1 + expect(bob.reload.visible_shareables(Post).size).to eq(1) post_in_db = StatusMessage.find(@post.id) - post_in_db.comments.should == [] + expect(post_in_db.comments).to eq([]) receive_with_zord(bob, alice.person, @xml) - post_in_db.comments(true).first.author.should == eve.person + expect(post_in_db.comments(true).first.author).to eq(eve.person) end it 'should correctly marshal a stranger for the downstream user' do @@ -226,18 +226,18 @@ describe 'a user receives a post' do remote_person.attributes.delete(:id) # leaving a nil id causes it to try to save with id set to NULL in postgres m = double() - Webfinger.should_receive(:new).twice.with(eve.person.diaspora_handle).and_return(m) + expect(Webfinger).to receive(:new).twice.with(eve.person.diaspora_handle).and_return(m) remote_person.save(:validate => false) remote_person.profile = FactoryGirl.create(:profile, :person => remote_person) - m.should_receive(:fetch).twice.and_return(remote_person) + expect(m).to receive(:fetch).twice.and_return(remote_person) - bob.reload.visible_shareables(Post).size.should == 1 + expect(bob.reload.visible_shareables(Post).size).to eq(1) post_in_db = StatusMessage.find(@post.id) - post_in_db.comments.should == [] + expect(post_in_db.comments).to eq([]) receive_with_zord(bob, alice.person, @xml) - post_in_db.comments(true).first.author.should == remote_person + expect(post_in_db.comments(true).first.author).to eq(remote_person) end end @@ -279,8 +279,8 @@ describe 'a user receives a post' do receive_with_zord(@local_luke, @remote_raphael, xml) old_time = Time.now+1 receive_with_zord(@local_leia, @remote_raphael, xml) - (Post.find_by_guid @post.guid).updated_at.should be < old_time - (Post.find_by_guid @post.guid).created_at.should be < old_time + expect((Post.find_by_guid @post.guid).updated_at).to be < old_time + expect((Post.find_by_guid @post.guid).created_at).to be < old_time end it 'does not update the post if a new one is sent with a new created_at' do @@ -290,7 +290,7 @@ describe 'a user receives a post' do receive_with_zord(@local_luke, @remote_raphael, xml) @post = FactoryGirl.build(:status_message, :text => 'hey', :guid => '12313123', :author => @remote_raphael, :created_at => 2.days.ago) receive_with_zord(@local_luke, @remote_raphael, xml) - (Post.find_by_guid @post.guid).created_at.day.should == old_time.day + expect((Post.find_by_guid @post.guid).created_at.day).to eq(old_time.day) end end @@ -305,7 +305,7 @@ describe 'a user receives a post' do zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml) zord.perform! - bob.visible_shareables(Post).include?(post).should be true + expect(bob.visible_shareables(Post).include?(post)).to be true end end @@ -366,8 +366,8 @@ describe 'a user receives a post' do #Check that marshaled profile is the same as old profile person = Person.find(person.id) - person.profile.first_name.should == new_profile.first_name - person.profile.last_name.should == new_profile.last_name - person.profile.image_url.should == new_profile.image_url + expect(person.profile.first_name).to eq(new_profile.first_name) + expect(person.profile.last_name).to eq(new_profile.last_name) + expect(person.profile.image_url).to eq(new_profile.image_url) end end diff --git a/spec/integration/tag_people_spec.rb b/spec/integration/tag_people_spec.rb index 049ef9375ff085c45ed085d6fb95d6d9e7df00b2..cf4e2e1861a3e0a6518dff62bb8b5faf0bd6c58d 100644 --- a/spec/integration/tag_people_spec.rb +++ b/spec/integration/tag_people_spec.rb @@ -1,28 +1,28 @@ require 'spec_helper' -describe TagsController, type: :controller do +describe TagsController do describe 'will_paginate people on the tag page' do let(:people) { (1..2).map { FactoryGirl.create(:person) } } let(:tag) { "diaspora" } before do Stream::Tag.any_instance.stub(people_per_page: 1) - Person.should_receive(:profile_tagged_with).with(/#{tag}/).twice.and_return(people) + expect(Person).to receive(:profile_tagged_with).with(/#{tag}/).twice.and_return(people) end it 'paginates the people set' do get "/tags/#{tag}" expect(response.status).to eq(200) - response.body.should match(/div class="pagination"/) - response.body.should match(/href="\/tags\/#{tag}\?page=2"/) + expect(response.body).to match(/div class="pagination"/) + expect(response.body).to match(/href="\/tags\/#{tag}\?page=2"/) end it 'fetches the second page' do get "/tags/#{tag}", page: 2 expect(response.status).to eq(200) - response.body.should match(/<em class="current">2<\/em>/) + expect(response.body).to match(/<em class="current">2<\/em>/) end end end diff --git a/spec/lib/account_deleter_spec.rb b/spec/lib/account_deleter_spec.rb index 339224c48d85fa68598bd61a9c8e89e094792c37..7c890757eb5cf2eed6586c7709e7ace90e21b113 100644 --- a/spec/lib/account_deleter_spec.rb +++ b/spec/lib/account_deleter_spec.rb @@ -11,8 +11,8 @@ describe AccountDeleter do end it "attaches the user" do - AccountDeleter.new(bob.person.diaspora_handle).user.should == bob - AccountDeleter.new(remote_raphael.diaspora_handle).user.should == nil + expect(AccountDeleter.new(bob.person.diaspora_handle).user).to eq(bob) + expect(AccountDeleter.new(remote_raphael.diaspora_handle).user).to eq(nil) end describe '#perform' do @@ -38,7 +38,7 @@ describe AccountDeleter do (user_removal_methods + person_removal_methods).each do |method| it "calls ##{method.to_s}" do - @account_deletion.should_receive(method) + expect(@account_deletion).to receive(method) end end end @@ -55,14 +55,14 @@ describe AccountDeleter do (user_removal_methods).each do |method| it "does not call ##{method.to_s}" do - @person_deletion.should_not_receive(method) + expect(@person_deletion).not_to receive(method) end end (person_removal_methods).each do |method| it "calls ##{method.to_s}" do - @person_deletion.should_receive(method) + expect(@person_deletion).to receive(method) end end end @@ -73,8 +73,8 @@ describe AccountDeleter do it 'removes all standard user associaltions' do @account_deletion.normal_ar_user_associates_to_delete.each do |asso| association_double = double - association_double.should_receive(:destroy) - bob.should_receive(asso).and_return([association_double]) + expect(association_double).to receive(:destroy) + expect(bob).to receive(asso).and_return([association_double]) end @account_deletion.delete_standard_user_associations @@ -88,8 +88,8 @@ describe AccountDeleter do it 'removes all standard person associaltions' do @account_deletion.normal_ar_person_associates_to_delete.each do |asso| association_double = double - association_double.should_receive(:destroy_all) - bob.person.should_receive(asso).and_return(association_double) + expect(association_double).to receive(:destroy_all) + expect(bob.person).to receive(asso).and_return(association_double) end @account_deletion.delete_standard_person_associations @@ -99,8 +99,8 @@ describe AccountDeleter do describe "#disassociate_invitations" do it "sets invitations_from_me to be admin invitations" do invites = [double] - bob.stub(:invitations_from_me).and_return(invites) - invites.first.should_receive(:convert_to_admin!) + allow(bob).to receive(:invitations_from_me).and_return(invites) + expect(invites.first).to receive(:convert_to_admin!) @account_deletion.disassociate_invitations end end @@ -108,7 +108,7 @@ describe AccountDeleter do context 'person associations' do describe '#disconnect_contacts' do it "deletes all of user's contacts" do - bob.contacts.should_receive(:destroy_all) + expect(bob.contacts).to receive(:destroy_all) @account_deletion.disconnect_contacts end end @@ -116,28 +116,28 @@ describe AccountDeleter do describe '#delete_contacts_of_me' do it 'deletes all the local contact objects where deleted account is the person' do contacts = double - Contact.should_receive(:all_contacts_of_person).with(bob.person).and_return(contacts) - contacts.should_receive(:destroy_all) + expect(Contact).to receive(:all_contacts_of_person).with(bob.person).and_return(contacts) + expect(contacts).to receive(:destroy_all) @account_deletion.delete_contacts_of_me end end describe '#tombstone_person_and_profile' do it 'calls clear_profile! on person' do - @account_deletion.person.should_receive(:clear_profile!) + expect(@account_deletion.person).to receive(:clear_profile!) @account_deletion.tombstone_person_and_profile end it 'calls lock_access! on person' do - @account_deletion.person.should_receive(:lock_access!) + expect(@account_deletion.person).to receive(:lock_access!) @account_deletion.tombstone_person_and_profile end end describe "#remove_conversation_visibilities" do it "removes the conversation visibility for the deleted user" do vis = double - ConversationVisibility.should_receive(:where).with(hash_including(:person_id => bob.person.id)).and_return(vis) - vis.should_receive(:destroy_all) + expect(ConversationVisibility).to receive(:where).with(hash_including(:person_id => bob.person.id)).and_return(vis) + expect(vis).to receive(:destroy_all) @account_deletion.remove_conversation_visibilities end end @@ -146,8 +146,8 @@ describe AccountDeleter do describe "#remove_person_share_visibilities" do it 'removes the share visibilities for a person ' do @s_vis = double - ShareVisibility.should_receive(:for_contacts_of_a_person).with(bob.person).and_return(@s_vis) - @s_vis.should_receive(:destroy_all) + expect(ShareVisibility).to receive(:for_contacts_of_a_person).with(bob.person).and_return(@s_vis) + expect(@s_vis).to receive(:destroy_all) @account_deletion.remove_share_visibilities_on_persons_posts end @@ -156,8 +156,8 @@ describe AccountDeleter do describe "#remove_share_visibilities_by_contacts_of_user" do it 'removes the share visibilities for a user' do @s_vis = double - ShareVisibility.should_receive(:for_a_users_contacts).with(bob).and_return(@s_vis) - @s_vis.should_receive(:destroy_all) + expect(ShareVisibility).to receive(:for_a_users_contacts).with(bob).and_return(@s_vis) + expect(@s_vis).to receive(:destroy_all) @account_deletion.remove_share_visibilities_on_contacts_posts end @@ -165,19 +165,19 @@ describe AccountDeleter do describe "#tombstone_user" do it 'calls strip_model on user' do - bob.should_receive(:clear_account!) + expect(bob).to receive(:clear_account!) @account_deletion.tombstone_user end end it 'has all user association keys accounted for' do all_keys = (@account_deletion.normal_ar_user_associates_to_delete + @account_deletion.special_ar_user_associations + @account_deletion.ignored_ar_user_associations) - all_keys.sort{|x, y| x.to_s <=> y.to_s}.should == User.reflections.keys.sort{|x, y| x.to_s <=> y.to_s} + expect(all_keys.sort{|x, y| x.to_s <=> y.to_s}).to eq(User.reflections.keys.sort{|x, y| x.to_s <=> y.to_s}) end it 'has all person association keys accounted for' do all_keys = (@account_deletion.normal_ar_person_associates_to_delete + @account_deletion.ignored_or_special_ar_person_associations) - all_keys.sort{|x, y| x.to_s <=> y.to_s}.should == Person.reflections.keys.sort{|x, y| x.to_s <=> y.to_s} + expect(all_keys.sort{|x, y| x.to_s <=> y.to_s}).to eq(Person.reflections.keys.sort{|x, y| x.to_s <=> y.to_s}) end end diff --git a/spec/lib/configuration_methods_spec.rb b/spec/lib/configuration_methods_spec.rb index 654dc4933f1bcb468a5367454cf38a2be1e268c5..5ca9e3ca21e88e9549c2ff74a53f59c9ce3c6745 100644 --- a/spec/lib/configuration_methods_spec.rb +++ b/spec/lib/configuration_methods_spec.rb @@ -17,37 +17,37 @@ describe Configuration::Methods do it "properly parses the pod url" do @settings.environment.url = "http://example.org/" - @settings.pod_uri.scheme.should == "http" - @settings.pod_uri.host.should == "example.org" + expect(@settings.pod_uri.scheme).to eq("http") + expect(@settings.pod_uri.host).to eq("example.org") end it "adds a trailing slash if there isn't one" do @settings.environment.url = "http://example.org" - @settings.pod_uri.to_s.should == "http://example.org/" + expect(@settings.pod_uri.to_s).to eq("http://example.org/") end it "does not add an extra trailing slash" do @settings.environment.url = "http://example.org/" - @settings.pod_uri.to_s.should == "http://example.org/" + expect(@settings.pod_uri.to_s).to eq("http://example.org/") end it "adds http:// on the front if it's missing" do @settings.environment.url = "example.org/" - @settings.pod_uri.to_s.should == "http://example.org/" + expect(@settings.pod_uri.to_s).to eq("http://example.org/") end it "does not add a prefix if there already is https:// on the front" do @settings.environment.url = "https://example.org/" - @settings.pod_uri.to_s.should == "https://example.org/" + expect(@settings.pod_uri.to_s).to eq("https://example.org/") end end describe "#bare_pod_uri" do it 'is #pod_uri.authority stripping www.' do pod_uri = double - @settings.stub(:pod_uri).and_return(pod_uri) - pod_uri.should_receive(:authority).and_return("www.example.org") - @settings.bare_pod_uri.should == 'example.org' + allow(@settings).to receive(:pod_uri).and_return(pod_uri) + expect(pod_uri).to receive(:authority).and_return("www.example.org") + expect(@settings.bare_pod_uri).to eq('example.org') end end @@ -55,44 +55,44 @@ describe Configuration::Methods do it "includes the enabled services only" do services = double enabled = double - enabled.stub(:enable?).and_return(true) + allow(enabled).to receive(:enable?).and_return(true) disabled = double - disabled.stub(:enable?).and_return(false) - services.stub(:twitter).and_return(enabled) - services.stub(:tumblr).and_return(enabled) - services.stub(:facebook).and_return(disabled) - services.stub(:wordpress).and_return(disabled) - @settings.stub(:services).and_return(services) - @settings.configured_services.should include :twitter - @settings.configured_services.should include :tumblr - @settings.configured_services.should_not include :facebook - @settings.configured_services.should_not include :wordpress + allow(disabled).to receive(:enable?).and_return(false) + allow(services).to receive(:twitter).and_return(enabled) + allow(services).to receive(:tumblr).and_return(enabled) + allow(services).to receive(:facebook).and_return(disabled) + allow(services).to receive(:wordpress).and_return(disabled) + allow(@settings).to receive(:services).and_return(services) + expect(@settings.configured_services).to include :twitter + expect(@settings.configured_services).to include :tumblr + expect(@settings.configured_services).not_to include :facebook + expect(@settings.configured_services).not_to include :wordpress end end describe "#version_string" do before do @version = double - @version.stub(:number).and_return("0.0.0.0") - @version.stub(:release?).and_return(true) - @settings.stub(:version).and_return(@version) - @settings.stub(:git_available?).and_return(false) + allow(@version).to receive(:number).and_return("0.0.0.0") + allow(@version).to receive(:release?).and_return(true) + allow(@settings).to receive(:version).and_return(@version) + allow(@settings).to receive(:git_available?).and_return(false) @settings.instance_variable_set(:@version_string, nil) end it "includes the version" do - @settings.version_string.should include @version.number + expect(@settings.version_string).to include @version.number end context "with git available" do before do - @settings.stub(:git_available?).and_return(true) - @settings.stub(:git_revision).and_return("1234567890") + allow(@settings).to receive(:git_available?).and_return(true) + allow(@settings).to receive(:git_revision).and_return("1234567890") end it "includes the 'patchlevel'" do - @settings.version_string.should include "-p#{@settings.git_revision[0..7]}" - @settings.version_string.should_not include @settings.git_revision[0..8] + expect(@settings.version_string).to include "-p#{@settings.git_revision[0..7]}" + expect(@settings.version_string).not_to include @settings.git_revision[0..8] end end end @@ -104,7 +104,7 @@ describe Configuration::Methods do end it "uses that" do - @settings.get_redis_options[:url].should match "myserver" + expect(@settings.get_redis_options[:url]).to match "myserver" end end @@ -115,7 +115,7 @@ describe Configuration::Methods do end it "uses that" do - @settings.get_redis_options[:url].should match "yourserver" + expect(@settings.get_redis_options[:url]).to match "yourserver" end end @@ -127,7 +127,7 @@ describe Configuration::Methods do end it "uses that" do - @settings.get_redis_options[:url].should match "ourserver" + expect(@settings.get_redis_options[:url]).to match "ourserver" end end @@ -139,7 +139,7 @@ describe Configuration::Methods do end it "uses that" do - @settings.get_redis_options[:url].should match "/tmp/redis.sock" + expect(@settings.get_redis_options[:url]).to match "/tmp/redis.sock" end end end @@ -148,9 +148,9 @@ describe Configuration::Methods do context "with a relative log set" do it "joins that with Rails.root" do path = "/some/path/" - Rails.stub(:root).and_return(double(join: path)) + allow(Rails).to receive(:root).and_return(double(join: path)) @settings.environment.sidekiq.log = "relative_path" - @settings.sidekiq_log.should match path + expect(@settings.sidekiq_log).to match path end end @@ -158,7 +158,7 @@ describe Configuration::Methods do it "just returns that" do path = "/foobar.log" @settings.environment.sidekiq.log = path - @settings.sidekiq_log.should == path + expect(@settings.sidekiq_log).to eq(path) end end end diff --git a/spec/lib/diaspora/encryptable_spec.rb b/spec/lib/diaspora/encryptable_spec.rb index 1fefbf403c3e25a684850f0dce7f216595c93f9f..7419b7f61c1b63ca7a1428c2c2a4ee8359b148b2 100644 --- a/spec/lib/diaspora/encryptable_spec.rb +++ b/spec/lib/diaspora/encryptable_spec.rb @@ -11,19 +11,19 @@ describe Diaspora::Encryptable do describe '#sign_with_key' do it 'signs the object with RSA256 signature' do sig = @comment.sign_with_key bob.encryption_key - bob.public_key.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(sig), @comment.signable_string).should be true + expect(bob.public_key.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(sig), @comment.signable_string)).to be true end end describe '#verify_signature' do it 'verifies SHA256 signatures' do sig = @comment.sign_with_key bob.encryption_key - @comment.verify_signature(sig, bob.person).should be true + expect(@comment.verify_signature(sig, bob.person)).to be true end it 'does not verify the fallback after rollout window' do sig = Base64.strict_encode64(bob.encryption_key.sign( "SHA", @comment.signable_string )) - @comment.verify_signature(sig, bob.person).should be false + expect(@comment.verify_signature(sig, bob.person)).to be false end end end diff --git a/spec/lib/diaspora/exporter_spec.rb b/spec/lib/diaspora/exporter_spec.rb index 9db71fbfe45bde60b6b3ef856748f25eb3b1758f..63d3c2316a88f25f8fafe5d93a4d375144053152 100644 --- a/spec/lib/diaspora/exporter_spec.rb +++ b/spec/lib/diaspora/exporter_spec.rb @@ -55,8 +55,8 @@ describe Diaspora::Exporter do let(:aspects_xml) { exported.xpath('//aspects').to_s } it 'includes the post_ids' do - aspects_xml.should include @status_message1.id.to_s - aspects_xml.should include @status_message2.id.to_s + expect(aspects_xml).to include @status_message1.id.to_s + expect(aspects_xml).to include @status_message2.id.to_s end end @@ -71,14 +71,14 @@ describe Diaspora::Exporter do let(:contacts_xml) {exported.xpath('//contacts').to_s} it "includes a person's guid" do - contacts_xml.should include @user3.person.guid + expect(contacts_xml).to include @user3.person.guid end it "includes the names of all aspects they are in" do #contact specific xml needs to be tested - @user1.contacts.find_by_person_id(@user3.person.id).aspects.count.should > 0 + expect(@user1.contacts.find_by_person_id(@user3.person.id).aspects.count).to be > 0 @user1.contacts.find_by_person_id(@user3.person.id).aspects.each { |aspect| - contacts_xml.should include aspect.name + expect(contacts_xml).to include aspect.name } end end @@ -87,29 +87,29 @@ describe Diaspora::Exporter do let(:people_xml) {exported.xpath('//people').to_s} it 'includes their guid' do - people_xml.should include @user3.person.guid + expect(people_xml).to include @user3.person.guid end it 'includes their profile' do - people_xml.should include @user3.person.profile.first_name - people_xml.should include @user3.person.profile.last_name + expect(people_xml).to include @user3.person.profile.first_name + expect(people_xml).to include @user3.person.profile.last_name end it 'includes their public key' do - people_xml.should include @user3.person.exported_key + expect(people_xml).to include @user3.person.exported_key end it 'includes their diaspora handle' do - people_xml.should include @user3.person.diaspora_handle + expect(people_xml).to include @user3.person.diaspora_handle end end context '<posts>' do let(:posts_xml) {exported.xpath('//posts').to_s} it "includes many posts' xml" do - posts_xml.should include @status_message1.text - posts_xml.should include @status_message2.text - posts_xml.should_not include @status_message3.text + expect(posts_xml).to include @status_message1.text + expect(posts_xml).to include @status_message2.text + expect(posts_xml).not_to include @status_message3.text end it "includes the post's created at time" do @@ -120,7 +120,7 @@ describe Diaspora::Exporter do status.to_s.include?(@status_message1.guid) end.xpath('created_at').text - Time.zone.parse(created_at_text).to_i.should == @status_message1.created_at.to_i + expect(Time.zone.parse(created_at_text).to_i).to eq(@status_message1.created_at.to_i) end end end diff --git a/spec/lib/diaspora/federated/relayable_retraction_spec.rb b/spec/lib/diaspora/federated/relayable_retraction_spec.rb index ad9888e3c659d388fa74dfc343d615b5bd71170e..baf88a6eb56ec3d86a7485e06f7a3a7c95c64bd6 100644 --- a/spec/lib/diaspora/federated/relayable_retraction_spec.rb +++ b/spec/lib/diaspora/federated/relayable_retraction_spec.rb @@ -20,14 +20,14 @@ describe RelayableRetraction do describe "#parent" do it "delegates to to target" do - @retraction.target.should_receive(:parent) + expect(@retraction.target).to receive(:parent) @retraction.parent end end describe "#parent_author" do it "delegates to target" do - @retraction.target.should_receive(:parent_author) + expect(@retraction.target).to receive(:parent_author) @retraction.parent_author end end @@ -35,7 +35,7 @@ describe RelayableRetraction do describe '#subscribers' do it 'delegates it to target' do arg = double() - @retraction.target.should_receive(:subscribers).with(arg) + expect(@retraction.target).to receive(:subscribers).with(arg) @retraction.subscribers(arg) end end @@ -48,7 +48,7 @@ describe RelayableRetraction do @retraction.instance_variable_set(:@target, nil) @retraction.target_guid = '135245' - @retraction.should_not_receive(:perform) + expect(@retraction).not_to receive(:perform) @retraction.receive(@local_luke, @remote_raphael) end @@ -60,21 +60,21 @@ describe RelayableRetraction do end it 'signs' do - @retraction.should_receive(:sign_with_key) do |key| - key.to_s.should == @recipient.encryption_key.to_s + expect(@retraction).to receive(:sign_with_key) do |key| + expect(key.to_s).to eq(@recipient.encryption_key.to_s) end @retraction.receive(@recipient, @comment.author) end it 'dispatches' do zord = double() - zord.should_receive(:post) - Postzord::Dispatcher.should_receive(:build).with(@local_luke, @retraction).and_return zord + expect(zord).to receive(:post) + expect(Postzord::Dispatcher).to receive(:build).with(@local_luke, @retraction).and_return zord @retraction.receive(@recipient, @comment.author) end it 'performs' do - @retraction.should_receive(:perform).with(@local_luke) + expect(@retraction).to receive(:perform).with(@local_luke) @retraction.receive(@recipient, @comment.author) end end @@ -85,17 +85,17 @@ describe RelayableRetraction do @retraction = described_class.allocate @retraction.sender = @remote_raphael @retraction.target = @comment - @retraction.stub(:parent_author_signature_valid?).and_return(true) + allow(@retraction).to receive(:parent_author_signature_valid?).and_return(true) @recipient = @local_luke end it 'performs' do - @retraction.should_receive(:perform).with(@recipient) + expect(@retraction).to receive(:perform).with(@recipient) @retraction.receive(@recipient, @remote_raphael) end it 'does not dispatch' do - Postzord::Dispatcher.should_not_receive(:build) + expect(Postzord::Dispatcher).not_to receive(:build) @retraction.receive(@recipient, @remote_raphael) end end @@ -112,20 +112,20 @@ describe RelayableRetraction do describe '#to_xml' do it 'serializes target_guid' do - @xml.should include(@comment.guid) + expect(@xml).to include(@comment.guid) end it 'serializes target_type' do - @xml.should include(@comment.class.to_s) + expect(@xml).to include(@comment.class.to_s) end it 'serializes sender_handle' do - @xml.should include(@local_leia.diaspora_handle) + expect(@xml).to include(@local_leia.diaspora_handle) end it 'serializes signatures' do - @xml.should include('TARGETSIGNATURE') - @xml.should include('PARENTSIGNATURE') + expect(@xml).to include('TARGETSIGNATURE') + expect(@xml).to include('PARENTSIGNATURE') end end @@ -135,16 +135,16 @@ describe RelayableRetraction do end it 'marshals the target' do - @marshalled.target.should == @comment + expect(@marshalled.target).to eq(@comment) end it 'marshals the sender' do - @marshalled.sender.should == @local_leia.person + expect(@marshalled.sender).to eq(@local_leia.person) end it 'marshals the signature' do - @marshalled.target_author_signature.should == 'TARGETSIGNATURE' - @marshalled.parent_author_signature.should == 'PARENTSIGNATURE' + expect(@marshalled.target_author_signature).to eq('TARGETSIGNATURE') + expect(@marshalled.parent_author_signature).to eq('PARENTSIGNATURE') end end end diff --git a/spec/lib/diaspora/federated/request_spec.rb b/spec/lib/diaspora/federated/request_spec.rb index a0d77a23717073b8dbe90df69b0045d0cd2b3fee..c6b1fe1a1836c8b7303a9a4ca361130a568ca30b 100644 --- a/spec/lib/diaspora/federated/request_spec.rb +++ b/spec/lib/diaspora/federated/request_spec.rb @@ -15,35 +15,35 @@ describe Request do end it 'is valid' do - @request.sender.should == alice.person - @request.recipient.should == eve.person - @request.aspect.should == @aspect - @request.should be_valid + expect(@request.sender).to eq(alice.person) + expect(@request.recipient).to eq(eve.person) + expect(@request.aspect).to eq(@aspect) + expect(@request).to be_valid end it 'is from a person' do @request.sender = nil - @request.should_not be_valid + expect(@request).not_to be_valid end it 'is to a person' do @request.recipient = nil - @request.should_not be_valid + expect(@request).not_to be_valid end it 'is not necessarily into an aspect' do @request.aspect = nil - @request.should be_valid + expect(@request).to be_valid end it 'is not from an existing friend' do Contact.create(:user => eve, :person => alice.person, :aspects => [eve.aspects.first]) - @request.should_not be_valid + expect(@request).not_to be_valid end it 'is not to yourself' do @request = described_class.diaspora_initialize(:from => alice.person, :to => alice.person, :into => @aspect) - @request.should_not be_valid + expect(@request).not_to be_valid end end @@ -54,23 +54,23 @@ describe Request do request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) alice.contacts.create(:person_id => person.id) - request.notification_type(alice, person).should == Notifications::StartedSharing + expect(request.notification_type(alice, person)).to eq(Notifications::StartedSharing) end end describe '#subscribers' do it 'returns an array with to field on a request' do request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) - request.subscribers(alice).should =~ [eve.person] + expect(request.subscribers(alice)).to match_array([eve.person]) end end describe '#receive' do it 'creates a contact' do request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) - lambda{ + expect{ request.receive(eve, alice.person) - }.should change{ + }.to change{ eve.contacts(true).size }.by(1) end @@ -78,10 +78,10 @@ describe Request do it 'sets mutual if a contact already exists' do alice.share_with(eve.person, alice.aspects.first) - lambda { + expect { described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) - }.should change { + }.to change { alice.contacts.find_by_person_id(eve.person.id).mutual? }.from(false).to(true) @@ -90,7 +90,7 @@ describe Request do it 'sets sharing' do described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) - alice.contact_for(eve.person).should be_sharing + expect(alice.contact_for(eve.person)).to be_sharing end it 'shares back if auto_following is enabled' do @@ -101,7 +101,7 @@ describe Request do described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) - eve.contact_for( alice.person ).should be_sharing + expect(eve.contact_for( alice.person )).to be_sharing end it 'shares not back if auto_following is not enabled' do @@ -112,7 +112,7 @@ describe Request do described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) - eve.contact_for(alice.person).should be_nil + expect(eve.contact_for(alice.person)).to be_nil end it 'shares not back if already sharing' do @@ -124,7 +124,7 @@ describe Request do :receiving => true, :sharing => false contact.save - alice.should_not_receive(:share_with) + expect(alice).not_to receive(:share_with) described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) @@ -139,10 +139,10 @@ describe Request do describe 'serialization' do it 'produces valid xml' do - @xml.should include alice.person.diaspora_handle - @xml.should include eve.person.diaspora_handle - @xml.should_not include alice.person.exported_key - @xml.should_not include alice.person.profile.first_name + expect(@xml).to include alice.person.diaspora_handle + expect(@xml).to include eve.person.diaspora_handle + expect(@xml).not_to include alice.person.exported_key + expect(@xml).not_to include alice.person.profile.first_name end end @@ -150,9 +150,9 @@ describe Request do it 'produces a request object' do marshalled = described_class.from_xml @xml - marshalled.sender.should == alice.person - marshalled.recipient.should == eve.person - marshalled.aspect.should be_nil + expect(marshalled.sender).to eq(alice.person) + expect(marshalled.recipient).to eq(eve.person) + expect(marshalled.aspect).to be_nil end end end diff --git a/spec/lib/diaspora/federated/retraction_spec.rb b/spec/lib/diaspora/federated/retraction_spec.rb index 8f556d47e5c32959e2cf5644f80e97aa4091faa6..11b1c49f91f61cf0510e262e9881ba5ccff28ac4 100644 --- a/spec/lib/diaspora/federated/retraction_spec.rb +++ b/spec/lib/diaspora/federated/retraction_spec.rb @@ -15,7 +15,7 @@ describe Retraction do it 'should have a post id after serialization' do retraction = described_class.for(@post) xml = retraction.to_xml.to_s - xml.include?(@post.guid.to_s).should == true + expect(xml.include?(@post.guid.to_s)).to eq(true) end end @@ -28,7 +28,7 @@ describe Retraction do end it 'returns the subscribers to the post for all objects other than person' do - @retraction.subscribers(alice).map(&:id).should =~ @wanted_subscribers.map(&:id) + expect(@retraction.subscribers(alice).map(&:id)).to match_array(@wanted_subscribers.map(&:id)) end it 'does not return the authors of reshares' do @@ -36,7 +36,7 @@ describe Retraction do @post.save! @wanted_subscribers -= [bob.person] - @retraction.subscribers(alice).map(&:id).should =~ @wanted_subscribers.map(&:id) + expect(@retraction.subscribers(alice).map(&:id)).to match_array(@wanted_subscribers.map(&:id)) end end @@ -45,15 +45,15 @@ describe Retraction do retraction = described_class.for(alice) obj = retraction.instance_variable_get(:@object) - lambda { + expect { retraction.subscribers(alice) - }.should raise_error + }.to raise_error end it 'returns manually set subscribers' do retraction = described_class.for(alice) retraction.subscribers = "fooey" - retraction.subscribers(alice).should == 'fooey' + expect(retraction.subscribers(alice)).to eq('fooey') end end end diff --git a/spec/lib/diaspora/federated/signed_retraction_spec.rb b/spec/lib/diaspora/federated/signed_retraction_spec.rb index 55433a0ab3fe11b94d7221be34eec07324fe0aed..332e9e9c45658a131aa77e91b2c5f719ee047c6d 100644 --- a/spec/lib/diaspora/federated/signed_retraction_spec.rb +++ b/spec/lib/diaspora/federated/signed_retraction_spec.rb @@ -11,11 +11,11 @@ describe SignedRetraction do it "dispatches the retraction onward to recipients of the recipient's reshare" do retraction = described_class.build(bob, @post) onward_retraction = retraction.dup - retraction.should_receive(:dup).and_return(onward_retraction) + expect(retraction).to receive(:dup).and_return(onward_retraction) dis = double - Postzord::Dispatcher.should_receive(:build).with(@resharer, onward_retraction).and_return(dis) - dis.should_receive(:post) + expect(Postzord::Dispatcher).to receive(:build).with(@resharer, onward_retraction).and_return(dis) + expect(dis).to receive(:post) retraction.perform(@resharer) end @@ -28,19 +28,19 @@ describe SignedRetraction do r.target_type = remote_post.type r.target_guid = remote_post.guid r.sender = remote_post.author - r.stub(:target_author_signature_valid?).and_return(true) + allow(r).to receive(:target_author_signature_valid?).and_return(true) } remote_retraction.dup.perform(bob) - Post.exists?(:id => remote_post.id).should be false + expect(Post.exists?(:id => remote_post.id)).to be false dis = double - Postzord::Dispatcher.should_receive(:build){ |sender, retraction| - sender.should == alice - retraction.sender.should == alice.person + expect(Postzord::Dispatcher).to receive(:build){ |sender, retraction| + expect(sender).to eq(alice) + expect(retraction.sender).to eq(alice.person) dis } - dis.should_receive(:post) + expect(dis).to receive(:post) remote_retraction.perform(alice) end end diff --git a/spec/lib/diaspora/federated_base_spec.rb b/spec/lib/diaspora/federated_base_spec.rb index a3fbcbaccfaecca5365353d801c63801bb1412bf..a2621e3c634b950d0ff8e2359fb110a11607b40d 100644 --- a/spec/lib/diaspora/federated_base_spec.rb +++ b/spec/lib/diaspora/federated_base_spec.rb @@ -13,7 +13,7 @@ describe Diaspora::Federated::Base do f = Foo.new - proc{ f.subscribers(1)}.should raise_error /override subscribers/ + expect{ f.subscribers(1)}.to raise_error /override subscribers/ end end end diff --git a/spec/lib/diaspora/fetcher/public_spec.rb b/spec/lib/diaspora/fetcher/public_spec.rb index 0ad5381b4cba8eb2989ae846ce2de2b931679b32..43f249cabdfbce25f4a3179a39bb8dfcf55e98b7 100644 --- a/spec/lib/diaspora/fetcher/public_spec.rb +++ b/spec/lib/diaspora/fetcher/public_spec.rb @@ -36,16 +36,16 @@ describe Diaspora::Fetcher::Public do it "sets the operation status on the person" do @person.reload - @person.fetch_status.should_not eql(Diaspora::Fetcher::Public::Status_Initial) - @person.fetch_status.should eql(Diaspora::Fetcher::Public::Status_Fetched) + expect(@person.fetch_status).not_to eql(Diaspora::Fetcher::Public::Status_Initial) + expect(@person.fetch_status).to eql(Diaspora::Fetcher::Public::Status_Fetched) end it "sets the @data variable to the parsed JSON data" do data = @fetcher.instance_eval { @data } - data.should_not be_nil - data.size.should eql JSON.parse(@fixture).size + expect(data).not_to be_nil + expect(data.size).to eql JSON.parse(@fixture).size end end @@ -66,7 +66,7 @@ describe Diaspora::Fetcher::Public do process_posts } after_count = Post.count - after_count.should eql(before_count + 10) + expect(after_count).to eql(before_count + 10) end it 'sets the operation status on the person' do @@ -75,8 +75,8 @@ describe Diaspora::Fetcher::Public do } @person.reload - @person.fetch_status.should_not eql(Diaspora::Fetcher::Public::Status_Initial) - @person.fetch_status.should eql(Diaspora::Fetcher::Public::Status_Processed) + expect(@person.fetch_status).not_to eql(Diaspora::Fetcher::Public::Status_Initial) + expect(@person.fetch_status).to eql(Diaspora::Fetcher::Public::Status_Processed) end context 'created post' do @@ -100,14 +100,14 @@ describe Diaspora::Fetcher::Public do date = ActiveSupport::TimeZone.new('UTC').parse(post['created_at']).to_i entry = StatusMessage.find_by_guid(post['guid']) - entry.created_at.to_i.should eql(date) + expect(entry.created_at.to_i).to eql(date) end end it 'copied the text correctly' do @data.each do |post| entry = StatusMessage.find_by_guid(post['guid']) - entry.raw_message.should eql(post['text']) + expect(entry.raw_message).to eql(post['text']) end end @@ -116,7 +116,7 @@ describe Diaspora::Fetcher::Public do date = @now.to_i entry = StatusMessage.find_by_guid(post['guid']) - entry.interacted_at.to_i.should eql(date) + expect(entry.interacted_at.to_i).to eql(date) end end end @@ -127,46 +127,46 @@ describe Diaspora::Fetcher::Public do describe '#qualifies_for_fetching?' do it "raises an error if the person doesn't exist" do - lambda { + expect { public_fetcher.instance_eval { @person = Person.by_account_identifier "someone@unknown.com" qualifies_for_fetching? } - }.should raise_error ActiveRecord::RecordNotFound + }.to raise_error ActiveRecord::RecordNotFound end it 'returns false if the person is unfetchable' do - public_fetcher.instance_eval { + expect(public_fetcher.instance_eval { @person = FactoryGirl.create(:person, {:fetch_status => Diaspora::Fetcher::Public::Status_Unfetchable}) qualifies_for_fetching? - }.should be false + }).to be false end it 'returns false and sets the person unfetchable for a local account' do user = FactoryGirl.create(:user) - public_fetcher.instance_eval { + expect(public_fetcher.instance_eval { @person = user.person qualifies_for_fetching? - }.should be false - user.person.fetch_status.should eql Diaspora::Fetcher::Public::Status_Unfetchable + }).to be false + expect(user.person.fetch_status).to eql Diaspora::Fetcher::Public::Status_Unfetchable end it 'returns false if the person is processing already (or has been processed)' do person = FactoryGirl.create(:person) person.fetch_status = Diaspora::Fetcher::Public::Status_Fetched person.save - public_fetcher.instance_eval { + expect(public_fetcher.instance_eval { @person = person qualifies_for_fetching? - }.should be false + }).to be false end it "returns true, if the user is remote and hasn't been fetched" do person = FactoryGirl.create(:person, {:diaspora_handle => 'neo@theone.net'}) - public_fetcher.instance_eval { + expect(public_fetcher.instance_eval { @person = person qualifies_for_fetching? - }.should be true + }).to be true end end @@ -177,35 +177,35 @@ describe Diaspora::Fetcher::Public do @person = person set_fetch_status Diaspora::Fetcher::Public::Status_Unfetchable } - @person.fetch_status.should eql Diaspora::Fetcher::Public::Status_Unfetchable + expect(@person.fetch_status).to eql Diaspora::Fetcher::Public::Status_Unfetchable public_fetcher.instance_eval { set_fetch_status Diaspora::Fetcher::Public::Status_Initial } - @person.fetch_status.should eql Diaspora::Fetcher::Public::Status_Initial + expect(@person.fetch_status).to eql Diaspora::Fetcher::Public::Status_Initial end end describe '#validate' do it "calls all validation helper methods" do - public_fetcher.should_receive(:check_existing).and_return(true) - public_fetcher.should_receive(:check_author).and_return(true) - public_fetcher.should_receive(:check_public).and_return(true) - public_fetcher.should_receive(:check_type).and_return(true) + expect(public_fetcher).to receive(:check_existing).and_return(true) + expect(public_fetcher).to receive(:check_author).and_return(true) + expect(public_fetcher).to receive(:check_public).and_return(true) + expect(public_fetcher).to receive(:check_type).and_return(true) - public_fetcher.instance_eval { validate({}) }.should be true + expect(public_fetcher.instance_eval { validate({}) }).to be true end end describe '#check_existing' do it 'returns false if a post with the same guid exists' do post = {'guid' => FactoryGirl.create(:status_message).guid} - public_fetcher.instance_eval { check_existing post }.should be false + expect(public_fetcher.instance_eval { check_existing post }).to be false end it 'returns true if the guid cannot be found' do post = {'guid' => SecureRandom.hex(8)} - public_fetcher.instance_eval { check_existing post }.should be true + expect(public_fetcher.instance_eval { check_existing post }).to be true end end @@ -219,36 +219,36 @@ describe Diaspora::Fetcher::Public do it "returns false if the person doesn't match" do post = { 'author' => { 'guid' => SecureRandom.hex(8) } } - public_fetcher.instance_eval { check_author post }.should be false + expect(public_fetcher.instance_eval { check_author post }).to be false end it "returns true if the persons match" do post = { 'author' => { 'guid' => some_person.guid } } - public_fetcher.instance_eval { check_author post }.should be true + expect(public_fetcher.instance_eval { check_author post }).to be true end end describe '#check_public' do it "returns false if the post is not public" do post = {'public' => false} - public_fetcher.instance_eval { check_public post }.should be false + expect(public_fetcher.instance_eval { check_public post }).to be false end it "returns true if the post is public" do post = {'public' => true} - public_fetcher.instance_eval { check_public post }.should be true + expect(public_fetcher.instance_eval { check_public post }).to be true end end describe '#check_type' do it "returns false if the type is anything other that 'StatusMessage'" do post = {'post_type'=>'Reshare'} - public_fetcher.instance_eval { check_type post }.should be false + expect(public_fetcher.instance_eval { check_type post }).to be false end it "returns true if the type is 'StatusMessage'" do post = {'post_type'=>'StatusMessage'} - public_fetcher.instance_eval { check_type post }.should be true + expect(public_fetcher.instance_eval { check_type post }).to be true end end end diff --git a/spec/lib/diaspora/markdownify_email_spec.rb b/spec/lib/diaspora/markdownify_email_spec.rb index f27d0afb1c755dc3ab0d12030486e0b213b42486..6a64f7f1dbf0cc06399ca29978363f7d049ca7b5 100644 --- a/spec/lib/diaspora/markdownify_email_spec.rb +++ b/spec/lib/diaspora/markdownify_email_spec.rb @@ -8,17 +8,17 @@ describe Diaspora::Markdownify::Email do it 'should autolink a hashtag' do markdownified = @html.preprocess("#tag") - markdownified.should == "[#tag](http://localhost:9887/tags/tag)" + expect(markdownified).to eq("[#tag](http://localhost:9887/tags/tag)") end it 'should autolink multiple hashtags' do markdownified = @html.preprocess("There are #two #Tags") - markdownified.should == "There are [#two](http://localhost:9887/tags/two) [#Tags](http://localhost:9887/tags/tags)" + expect(markdownified).to eq("There are [#two](http://localhost:9887/tags/two) [#Tags](http://localhost:9887/tags/tags)") end it 'should not autolink headers' do markdownified = @html.preprocess("# header") - markdownified.should == "# header" + expect(markdownified).to eq("# header") end end @@ -30,7 +30,7 @@ describe Diaspora::Markdownify::Email do it 'should render the message' do rendered = @markdown.render(@sample_text).strip - rendered.should == "<h1>Header</h1>\n\n<p><a href=\"http://localhost:9887/tags/messages\">#messages</a> containing <a href=\"http://localhost:9887/tags/hashtags\">#hashtags</a> should render properly</p>" + expect(rendered).to eq("<h1>Header</h1>\n\n<p><a href=\"http://localhost:9887/tags/messages\">#messages</a> containing <a href=\"http://localhost:9887/tags/hashtags\">#hashtags</a> should render properly</p>") end end end \ No newline at end of file diff --git a/spec/lib/diaspora/markdownify_spec.rb b/spec/lib/diaspora/markdownify_spec.rb index 41e6b28a29f84179a11505cffd9421e67b3dfb16..143a62f31e9c4ecce25e386cbcf25199ecdc4796 100644 --- a/spec/lib/diaspora/markdownify_spec.rb +++ b/spec/lib/diaspora/markdownify_spec.rb @@ -12,7 +12,7 @@ describe Diaspora::Markdownify::HTML do link = doc.css("a") - link.attr("target").value.should == "_blank" + expect(link.attr("target").value).to eq("_blank") end end end \ No newline at end of file diff --git a/spec/lib/diaspora/mentionable_spec.rb b/spec/lib/diaspora/mentionable_spec.rb index 5d9bdcc459b9d6af6893675e2f91216746576e14..d8f5235de3ec547998a577f41bc057bccc25dc1d 100644 --- a/spec/lib/diaspora/mentionable_spec.rb +++ b/spec/lib/diaspora/mentionable_spec.rb @@ -27,7 +27,7 @@ STR fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, @people) @people.each do |person| - fmt_msg.should include person_link(person, class: 'mention hovercardable') + expect(fmt_msg).to include person_link(person, class: 'mention hovercardable') end end @@ -36,7 +36,7 @@ STR fmt_msg = Diaspora::Mentionable.format(CGI::escapeHTML(raw_msg), @people) @people.each do |person| - fmt_msg.should include person_link(person, class: 'mention hovercardable') + expect(fmt_msg).to include person_link(person, class: 'mention hovercardable') end end @@ -47,8 +47,8 @@ STR fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, @people) - fmt_msg.should_not include(p.first_name) - fmt_msg.should include(">", "<", "'") # ">", "<", "'" + expect(fmt_msg).not_to include(p.first_name) + expect(fmt_msg).to include(">", "<", "'") # ">", "<", "'" end end @@ -57,33 +57,33 @@ STR fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, @people, plain_text: true) @people.each do |person| - fmt_msg.should include person.first_name + expect(fmt_msg).to include person.first_name end - fmt_msg.should_not include "<a", "</a>", "hovercardable" + expect(fmt_msg).not_to include "<a", "</a>", "hovercardable" end end it 'leaves the name of people that cannot be found' do fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, []) - fmt_msg.should eql @test_txt_plain + expect(fmt_msg).to eql @test_txt_plain end end describe '#people_from_string' do it 'extracts the mentioned people from the text' do ppl = Diaspora::Mentionable.people_from_string(@test_txt) - ppl.should include(*@people) + expect(ppl).to include(*@people) end describe 'returns an empty array if nobody was found' do it 'gets a post without mentions' do ppl = Diaspora::Mentionable.people_from_string("post w/o mentions") - ppl.should be_empty + expect(ppl).to be_empty end it 'gets a post with invalid handles' do ppl = Diaspora::Mentionable.people_from_string("@{a; xxx@xxx.xx} @{b; yyy@yyyy.yyy}") - ppl.should be_empty + expect(ppl).to be_empty end end end @@ -111,25 +111,25 @@ STR aspect_id = @user_A.aspects.where(name: 'generic').first.id txt = Diaspora::Mentionable.filter_for_aspects(@test_txt_C, @user_A, aspect_id) - txt.should include(@user_C.person.name) - txt.should include(local_or_remote_person_path(@user_C.person)) - txt.should_not include("href") - txt.should_not include(@mention_C) + expect(txt).to include(@user_C.person.name) + expect(txt).to include(local_or_remote_person_path(@user_C.person)) + expect(txt).not_to include("href") + expect(txt).not_to include(@mention_C) end it 'leaves mention, if contact is in a given aspect' do aspect_id = @user_A.aspects.where(name: 'generic').first.id txt = Diaspora::Mentionable.filter_for_aspects(@test_txt_B, @user_A, aspect_id) - txt.should include("user B") - txt.should include(@mention_B) + expect(txt).to include("user B") + expect(txt).to include(@mention_B) end it 'recognizes "all" as keyword for aspects' do txt = Diaspora::Mentionable.filter_for_aspects(@test_txt_BC, @user_A, "all") - txt.should include(@mention_B) - txt.should include(@mention_C) + expect(txt).to include(@mention_B) + expect(txt).to include(@mention_C) end end end diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index 4a7e6cf38120b9b52c2c26f82fa27ff6fe25acdb..c84ef4c17b169927417ef6545dd177c79568ad82 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -24,10 +24,10 @@ describe Diaspora::Parser do comment.delete xml = comment.to_diaspora_xml comment_from_xml = Diaspora::Parser.from_xml(xml) - comment_from_xml.diaspora_handle.should == @person.diaspora_handle - comment_from_xml.post.should == post - comment_from_xml.text.should == "Freedom!" - comment_from_xml.should_not be comment + expect(comment_from_xml.diaspora_handle).to eq(@person.diaspora_handle) + expect(comment_from_xml.post).to eq(post) + expect(comment_from_xml.text).to eq("Freedom!") + expect(comment_from_xml).not_to be comment end end end diff --git a/spec/lib/direction_detector_spec.rb b/spec/lib/direction_detector_spec.rb index 81c00cd2d5b47d1a0e0d35da77f3914f7b82c294..b19e854db128fff1ffb3b5d79f8ba3ef3a6962ff 100644 --- a/spec/lib/direction_detector_spec.rb +++ b/spec/lib/direction_detector_spec.rb @@ -26,65 +26,65 @@ describe String do describe "#stats_with_rtl_char?" do it 'returns true or false correctly' do - english.starts_with_rtl_char?.should be false - chinese.starts_with_rtl_char?.should be false - arabic.starts_with_rtl_char?.should be true - hebrew.starts_with_rtl_char?.should be true - hebrew_arabic.starts_with_rtl_char?.should be true + expect(english.starts_with_rtl_char?).to be false + expect(chinese.starts_with_rtl_char?).to be false + expect(arabic.starts_with_rtl_char?).to be true + expect(hebrew.starts_with_rtl_char?).to be true + expect(hebrew_arabic.starts_with_rtl_char?).to be true end it 'only looks at the first char' do - english_chinese.starts_with_rtl_char?.should be false - chinese_english.starts_with_rtl_char?.should be false - english_arabic.starts_with_rtl_char?.should be false - hebrew_english.starts_with_rtl_char?.should be true - arabic_chinese.starts_with_rtl_char?.should be true + expect(english_chinese.starts_with_rtl_char?).to be false + expect(chinese_english.starts_with_rtl_char?).to be false + expect(english_arabic.starts_with_rtl_char?).to be false + expect(hebrew_english.starts_with_rtl_char?).to be true + expect(arabic_chinese.starts_with_rtl_char?).to be true end it 'ignores whitespaces' do - " \n \r \t".starts_with_rtl_char?.should be false - " #{arabic} ".starts_with_rtl_char?.should be true + expect(" \n \r \t".starts_with_rtl_char?).to be false + expect(" #{arabic} ".starts_with_rtl_char?).to be true end end describe "#is_rtl?" do it 'returns true or false correctly' do - english.is_rtl?.should be false - chinese.is_rtl?.should be false - arabic.is_rtl?.should be true - hebrew.is_rtl?.should be true + expect(english.is_rtl?).to be false + expect(chinese.is_rtl?).to be false + expect(arabic.is_rtl?).to be true + expect(hebrew.is_rtl?).to be true end it 'respects all words' do - chinese_arabic.is_rtl?.should be true - chinese_hebrew.is_rtl?.should be true - english_hebrew.is_rtl?.should be false - hebrew_arabic.is_rtl?.should be true - "#{english} #{arabic} #{chinese}".is_rtl?.should be false - "Translated to arabic, Hello World means: #{arabic}".is_rtl?.should be false - "#{english} #{arabic} #{arabic}".is_rtl?.should be true + expect(chinese_arabic.is_rtl?).to be true + expect(chinese_hebrew.is_rtl?).to be true + expect(english_hebrew.is_rtl?).to be false + expect(hebrew_arabic.is_rtl?).to be true + expect("#{english} #{arabic} #{chinese}".is_rtl?).to be false + expect("Translated to arabic, Hello World means: #{arabic}".is_rtl?).to be false + expect("#{english} #{arabic} #{arabic}".is_rtl?).to be true end it "fallbacks to the first word if there's no majority" do - hebrew_english.is_rtl?.should be true - english_hebrew.is_rtl?.should be false - arabic_english.is_rtl?.should be true - english_arabic.is_rtl?.should be false + expect(hebrew_english.is_rtl?).to be true + expect(english_hebrew.is_rtl?).to be false + expect(arabic_english.is_rtl?).to be true + expect(english_arabic.is_rtl?).to be false end it 'ignores whitespaces' do - " \n \r \t".is_rtl?.should be false - " #{arabic} ".is_rtl?.should be true + expect(" \n \r \t".is_rtl?).to be false + expect(" #{arabic} ".is_rtl?).to be true end end describe '#cleaned_is_rtl?' do it 'should clean the string' do - "RT: #{arabic}".cleaned_is_rtl?.should be true - "#{hebrew} RT: #{arabic}".cleaned_is_rtl?.should be true - "@foo #{arabic}".cleaned_is_rtl?.should be true - "#{hebrew} #example".cleaned_is_rtl?.should be true - "♺: #{arabic} ♻: #{hebrew}".cleaned_is_rtl?.should be true + expect("RT: #{arabic}".cleaned_is_rtl?).to be true + expect("#{hebrew} RT: #{arabic}".cleaned_is_rtl?).to be true + expect("@foo #{arabic}".cleaned_is_rtl?).to be true + expect("#{hebrew} #example".cleaned_is_rtl?).to be true + expect("♺: #{arabic} ♻: #{hebrew}".cleaned_is_rtl?).to be true end end end diff --git a/spec/lib/email_inviter_spec.rb b/spec/lib/email_inviter_spec.rb index 6220864ae6e3fa5d0c769bd9f2d5f5c4f2a552f4..68cd1197c723e75e151fedc367cbb27a02a4debc 100644 --- a/spec/lib/email_inviter_spec.rb +++ b/spec/lib/email_inviter_spec.rb @@ -9,53 +9,53 @@ describe EmailInviter do it 'has a list of emails' do inviter = EmailInviter.new(@emails, @user) - inviter.emails.should_not be_empty + expect(inviter.emails).not_to be_empty end it 'should parse three emails' do inviter = EmailInviter.new(@emails, @user) - inviter.emails.count.should == 3 + expect(inviter.emails.count).to eq(3) end it 'has an inviter' do inviter = EmailInviter.new(@emails, @user) - inviter.inviter.should_not be_nil + expect(inviter.inviter).not_to be_nil end it 'can have a message' do message = "you guys suck hard" inviter = EmailInviter.new("emails", @user, :message => message) - inviter.message.should == message + expect(inviter.message).to eq(message) end describe '#emails' do it 'rejects the inviter email if present' do inviter = EmailInviter.new(@emails + " #{@user.email}", @user) - inviter.emails.should_not include(@user.email) + expect(inviter.emails).not_to include(@user.email) end end describe 'language' do it 'defaults to english' do inviter = EmailInviter.new(@emails, @user) - inviter.locale.should == 'en' + expect(inviter.locale).to eq('en') end it 'should symbolize keys' do inviter = EmailInviter.new(@emails, @user, 'locale' => 'es') - inviter.locale.should == 'es' + expect(inviter.locale).to eq('es') end it 'listens to the langauge option' do inviter = EmailInviter.new(@emails, @user, :locale => 'es') - inviter.locale.should == 'es' + expect(inviter.locale).to eq('es') end end describe '#invitation_code' do it 'delegates to the user' do inviter = EmailInviter.new(@emails, @user) - inviter.invitation_code.should == @user.invitation_code + expect(inviter.invitation_code).to eq(@user.invitation_code) end end end diff --git a/spec/lib/encryptor_spec.rb b/spec/lib/encryptor_spec.rb index afc3c6005431704d6133a9609b0b8431cd503ad2..a4d8a709a57075b733dfce50b8915077964fca83 100644 --- a/spec/lib/encryptor_spec.rb +++ b/spec/lib/encryptor_spec.rb @@ -14,8 +14,8 @@ describe 'user encryption' do it 'should encrypt a string' do string = "Secretsauce" ciphertext = @user.person.encrypt string - ciphertext.include?(string).should be false - @user.decrypt(ciphertext).should == string + expect(ciphertext.include?(string)).to be false + expect(@user.decrypt(ciphertext)).to eq(string) end end end diff --git a/spec/lib/evil_query_spec.rb b/spec/lib/evil_query_spec.rb index c77cb916360df7b322ee3e04cbaed1aae484ead8..29c69d0d2571ce2fed8d44aca1036b907aefaec6 100644 --- a/spec/lib/evil_query_spec.rb +++ b/spec/lib/evil_query_spec.rb @@ -16,12 +16,12 @@ describe EvilQuery::Participation do it "includes posts liked by the user" do alice.like!(@status_message) - EvilQuery::Participation.new(alice).posts.should include(@status_message) + expect(EvilQuery::Participation.new(alice).posts).to include(@status_message) end it "includes posts commented by the user" do alice.comment!(@status_message, "hey") - EvilQuery::Participation.new(alice).posts.should include(@status_message) + expect(EvilQuery::Participation.new(alice).posts).to include(@status_message) end it "should include your statusMessages" do @@ -55,12 +55,12 @@ describe EvilQuery::Participation do let(:posts) {EvilQuery::Participation.new(alice).posts} it "doesn't include Posts that aren't acted on" do - posts.map(&:id).should_not include(@status_messageD.id) - posts.map(&:id).should =~ [@status_messageA.id, @status_messageB.id, @status_messageE.id] + expect(posts.map(&:id)).not_to include(@status_messageD.id) + expect(posts.map(&:id)).to match_array([@status_messageA.id, @status_messageB.id, @status_messageE.id]) end it "returns the posts that the user has commented on or liked with the most recently acted on ones first" do - posts.map(&:id).should == [@status_messageE.id, @status_messageA.id, @status_messageB.id] + expect(posts.map(&:id)).to eq([@status_messageE.id, @status_messageA.id, @status_messageB.id]) end end end diff --git a/spec/lib/hcard_spec.rb b/spec/lib/hcard_spec.rb index 4a898d9fb65a4fda99eca9fb93cd31f034efd851..86cab268be1bf7c173864a5884712737577a3972 100644 --- a/spec/lib/hcard_spec.rb +++ b/spec/lib/hcard_spec.rb @@ -8,12 +8,12 @@ describe HCard do it 'should parse an hcard' do raw_hcard = hcard_response hcard = HCard.build raw_hcard - hcard[:family_name].include?("Hamiltom").should be true - hcard[:given_name].include?("Alex").should be true - hcard[:photo].include?("thumb_large").should be true - hcard[:photo_medium].include?("thumb_medium").should be true - hcard[:photo_small].include?("thumb_small").should be true - hcard[:url].should == "http://localhost:3000/" - hcard[:searchable].should == "false" + expect(hcard[:family_name].include?("Hamiltom")).to be true + expect(hcard[:given_name].include?("Alex")).to be true + expect(hcard[:photo].include?("thumb_large")).to be true + expect(hcard[:photo_medium].include?("thumb_medium")).to be true + expect(hcard[:photo_small].include?("thumb_small")).to be true + expect(hcard[:url]).to eq("http://localhost:3000/") + expect(hcard[:searchable]).to eq("false") end end diff --git a/spec/lib/hydra_wrapper_spec.rb b/spec/lib/hydra_wrapper_spec.rb index de9f722fcefe64f11091ec060768849fd525a873..5a303052e5c2b8a121070a9928f2476c0af7dce2 100644 --- a/spec/lib/hydra_wrapper_spec.rb +++ b/spec/lib/hydra_wrapper_spec.rb @@ -17,9 +17,9 @@ describe HydraWrapper do dispatcher_class = "Postzord::Dispatcher::Private" wrapper = HydraWrapper.new user, @people, encoded_object_xml, dispatcher_class - wrapper.user.should == user - wrapper.people.should == @people - wrapper.encoded_object_xml.should == encoded_object_xml + expect(wrapper.user).to eq(user) + expect(wrapper.people).to eq(@people) + expect(wrapper.encoded_object_xml).to eq(encoded_object_xml) end end @@ -27,16 +27,16 @@ describe HydraWrapper do it 'delegates #run to the @hydra' do hydra = double.as_null_object @wrapper.instance_variable_set :@hydra, hydra - hydra.should_receive :run + expect(hydra).to receive :run @wrapper.run end end describe '#xml_factory' do it 'calls the salmon method on the dispatcher class (and memoizes)' do - Base64.stub(:decode64).and_return "#{@wrapper.encoded_object_xml} encoded" + allow(Base64).to receive(:decode64).and_return "#{@wrapper.encoded_object_xml} encoded" decoded = Base64.decode64 @wrapper.encoded_object_xml - @wrapper.dispatcher_class.should_receive(:salmon).with(@wrapper.user, decoded).once.and_return true + expect(@wrapper.dispatcher_class).to receive(:salmon).with(@wrapper.user, decoded).once.and_return true @wrapper.send :xml_factory @wrapper.send :xml_factory end @@ -44,32 +44,32 @@ describe HydraWrapper do describe '#grouped_people' do it 'groups people given their receive_urls' do - @wrapper.dispatcher_class.should_receive(:receive_url_for).and_return "foo.com", "bar.com", "bar.com" + expect(@wrapper.dispatcher_class).to receive(:receive_url_for).and_return "foo.com", "bar.com", "bar.com" - @wrapper.send(:grouped_people).should == {"foo.com" => [@people[0]], "bar.com" => @people[1,2]} + expect(@wrapper.send(:grouped_people)).to eq({"foo.com" => [@people[0]], "bar.com" => @people[1,2]}) end end describe '#enqueue_batch' do it 'calls #grouped_people' do - @wrapper.should_receive(:grouped_people).and_return [] + expect(@wrapper).to receive(:grouped_people).and_return [] @wrapper.enqueue_batch end it 'inserts a job for every group of people' do - Base64.stub(:decode64) + allow(Base64).to receive(:decode64) @wrapper.dispatcher_class = double salmon: double(xml_for: "<XML>") - @wrapper.stub(:grouped_people).and_return('https://foo.com' => @wrapper.people) - @wrapper.people.should_receive(:first).once - @wrapper.should_receive(:insert_job).with('https://foo.com', "<XML>", @wrapper.people).once + allow(@wrapper).to receive(:grouped_people).and_return('https://foo.com' => @wrapper.people) + expect(@wrapper.people).to receive(:first).once + expect(@wrapper).to receive(:insert_job).with('https://foo.com', "<XML>", @wrapper.people).once @wrapper.enqueue_batch end it 'does not insert a job for a person whos xml returns false' do - Base64.stub(:decode64) - @wrapper.stub(:grouped_people).and_return('https://foo.com' => [double]) + allow(Base64).to receive(:decode64) + allow(@wrapper).to receive(:grouped_people).and_return('https://foo.com' => [double]) @wrapper.dispatcher_class = double salmon: double(xml_for: false) - @wrapper.should_not_receive :insert_job + expect(@wrapper).not_to receive :insert_job @wrapper.enqueue_batch end @@ -78,7 +78,7 @@ describe HydraWrapper do describe '#redirecting_to_https?!' do it 'does not execute unless response has a 3xx code' do resp = double code: 200 - @wrapper.send(:redirecting_to_https?, resp).should be false + expect(@wrapper.send(:redirecting_to_https?, resp)).to be false end it "returns true if just the protocol is different" do @@ -91,7 +91,7 @@ describe HydraWrapper do } ) - @wrapper.send(:redirecting_to_https?, resp).should be true + expect(@wrapper.send(:redirecting_to_https?, resp)).to be true end it "returns false if not just the protocol is different" do @@ -104,7 +104,7 @@ describe HydraWrapper do } ) - @wrapper.send(:redirecting_to_https?, resp).should be false + expect(@wrapper.send(:redirecting_to_https?, resp)).to be false end end end diff --git a/spec/lib/i18n_interpolation_fallbacks_spec.rb b/spec/lib/i18n_interpolation_fallbacks_spec.rb index 56a05e1c3c39865cf53fb3291e932ca861698d95..d8569b05a116055070124b63c84fdd8d1dcbc97a 100644 --- a/spec/lib/i18n_interpolation_fallbacks_spec.rb +++ b/spec/lib/i18n_interpolation_fallbacks_spec.rb @@ -7,20 +7,20 @@ require 'spec_helper' describe "i18n interpolation fallbacks" do describe "when string does not require interpolation arguments" do it "works normally" do - I18n.t('user.invalid', + expect(I18n.t('user.invalid', :resource_name => "user", :scope => "devise.failure", - :default => [:invalid, "invalid"]).should == "Invalid username or password." + :default => [:invalid, "invalid"])).to eq("Invalid username or password.") end end describe "when string requires interpolation arguments" do context "current locale has no fallbacks" do # ago: "%{time} ago" (in en.yml) it "returns the translation when all arguments are provided" do - I18n.t('ago', :time => "2 months").should == "2 months ago" + expect(I18n.t('ago', :time => "2 months")).to eq("2 months ago") end it "returns the translation without substitution when all arguments are omitted" do - I18n.t('ago').should == "%{time} ago" + expect(I18n.t('ago')).to eq("%{time} ago") end it "raises a MissingInterpolationArgument when arguments are wrong" do expect { I18n.t('ago', :not_time => "2 months") }.to raise_exception(I18n::MissingInterpolationArgument) @@ -37,19 +37,19 @@ describe "i18n interpolation fallbacks" do end describe "when all arguments are provided" do it "returns the locale's translation" do - I18n.t('nonexistant_key', :random_key => "Hi Alex,").should == "Hi Alex, here is some Italian" + expect(I18n.t('nonexistant_key', :random_key => "Hi Alex,")).to eq("Hi Alex, here is some Italian") end end describe "when no arguments are provided" do it "returns the locale's translation without substitution" do - I18n.t('nonexistant_key').should == "%{random_key} here is some Italian" + expect(I18n.t('nonexistant_key')).to eq("%{random_key} here is some Italian") end end describe "when arguments are wrong" do describe "when the English translation works" do it "falls back to English" do I18n.backend.store_translations('en', {"nonexistant_key" => "Working English translation"}) - I18n.t('nonexistant_key', :hey => "what").should == "Working English translation" + expect(I18n.t('nonexistant_key', :hey => "what")).to eq("Working English translation") end end describe "when the English translation does not work" do diff --git a/spec/lib/postzord/dispatcher_spec.rb b/spec/lib/postzord/dispatcher_spec.rb index b3605837e9d087e105a42ea90972111ae31990a6..d54d7bb810cf83b491846f1d93ac8c290a3e0627 100644 --- a/spec/lib/postzord/dispatcher_spec.rb +++ b/spec/lib/postzord/dispatcher_spec.rb @@ -9,31 +9,31 @@ describe Postzord::Dispatcher do @sm = FactoryGirl.create(:status_message, :public => true, :author => alice.person) @subscribers = [] 5.times{@subscribers << FactoryGirl.create(:person)} - @sm.stub(:subscribers).and_return(@subscribers) + allow(@sm).to receive(:subscribers).and_return(@subscribers) @xml = @sm.to_diaspora_xml end describe '.initialize' do it 'sets @sender, @object, @xml' do zord = Postzord::Dispatcher.build(alice, @sm) - zord.sender.should == alice - zord.object.should == @sm - zord.xml.should == @sm.to_diaspora_xml + expect(zord.sender).to eq(alice) + expect(zord.object).to eq(@sm) + expect(zord.xml).to eq(@sm.to_diaspora_xml) end context 'setting @subscribers' do it 'sets @subscribers from object' do - @sm.should_receive(:subscribers).and_return(@subscribers) + expect(@sm).to receive(:subscribers).and_return(@subscribers) zord = Postzord::Dispatcher.build(alice, @sm) - zord.subscribers.should == @subscribers + expect(zord.subscribers).to eq(@subscribers) end it 'accepts additional subscribers from opts' do new_person = FactoryGirl.create(:person) - @sm.should_receive(:subscribers).and_return(@subscribers) + expect(@sm).to receive(:subscribers).and_return(@subscribers) zord = Postzord::Dispatcher.build(alice, @sm, :additional_subscribers => new_person) - zord.subscribers.should == @subscribers | [new_person] + expect(zord.subscribers).to eq(@subscribers | [new_person]) end end @@ -55,17 +55,17 @@ describe Postzord::Dispatcher do describe '#post' do it 'calls Array#partition on subscribers' do @zord.instance_variable_set(:@subscribers, @subscribers) - @subscribers.should_receive(:partition).and_return([@remote_people, @local_people]) + expect(@subscribers).to receive(:partition).and_return([@remote_people, @local_people]) @zord.post end it 'calls #deliver_to_local with local people' do - @zord.should_receive(:deliver_to_local).with(@local_people) + expect(@zord).to receive(:deliver_to_local).with(@local_people) @zord.post end it 'calls #deliver_to_remote with remote people' do - @zord.should_receive(:deliver_to_remote).with(@remote_people) + expect(@zord).to receive(:deliver_to_remote).with(@remote_people) @zord.post end end @@ -90,17 +90,17 @@ describe Postzord::Dispatcher do end it 'calls deliver_to_local with local_luke' do - @mailman.should_receive(:deliver_to_local).with([@local_luke.person]) + expect(@mailman).to receive(:deliver_to_local).with([@local_luke.person]) @mailman.post end it 'calls deliver_to_remote with nobody' do - @mailman.should_receive(:deliver_to_remote).with([]) + expect(@mailman).to receive(:deliver_to_remote).with([]) @mailman.post end it 'does not call notify_users' do - @mailman.should_not_receive(:notify_users) + expect(@mailman).not_to receive(:notify_users) @mailman.post end end @@ -110,17 +110,17 @@ describe Postzord::Dispatcher do end it 'does not call deliver_to_local' do - @mailman.should_not_receive(:deliver_to_local) + expect(@mailman).not_to receive(:deliver_to_local) @mailman.post end it 'calls deliver_to_remote with remote raphael' do - @mailman.should_receive(:deliver_to_remote).with([@remote_raphael]) + expect(@mailman).to receive(:deliver_to_remote).with([@remote_raphael]) @mailman.post end it 'calls notify_users' do - @mailman.should_receive(:notify_users).with([@local_leia]) + expect(@mailman).to receive(:notify_users).with([@local_leia]) @mailman.post end end @@ -134,17 +134,17 @@ describe Postzord::Dispatcher do end it 'does not call deliver_to_local' do - @mailman.should_not_receive(:deliver_to_local) + expect(@mailman).not_to receive(:deliver_to_local) @mailman.post end it 'calls deliver_to_remote with remote_raphael' do - @mailman.should_receive(:deliver_to_remote).with([@remote_raphael]) + expect(@mailman).to receive(:deliver_to_remote).with([@remote_raphael]) @mailman.post end it 'calls notify_users' do - @mailman.should_receive(:notify_users).with([@local_leia]) + expect(@mailman).to receive(:notify_users).with([@local_leia]) @mailman.post end end @@ -157,17 +157,17 @@ describe Postzord::Dispatcher do end it 'does not call deliver_to_local' do - @mailman.should_not_receive(:deliver_to_local) + expect(@mailman).not_to receive(:deliver_to_local) @mailman.post end it 'calls deliver_to_remote with remote_raphael' do - @mailman.should_receive(:deliver_to_remote).with([@remote_raphael]) + expect(@mailman).to receive(:deliver_to_remote).with([@remote_raphael]) @mailman.post end it 'calls notify_users' do - @mailman.should_receive(:notify_users).with([@local_leia]) + expect(@mailman).to receive(:notify_users).with([@local_leia]) @mailman.post end end @@ -182,17 +182,17 @@ describe Postzord::Dispatcher do end it 'calls deliver_to_remote with remote_raphael' do - @mailman.should_receive(:deliver_to_remote).with([@remote_raphael]) + expect(@mailman).to receive(:deliver_to_remote).with([@remote_raphael]) @mailman.post end it 'calls deliver_to_local with nobody' do - @mailman.should_receive(:deliver_to_local).with([]) + expect(@mailman).to receive(:deliver_to_local).with([]) @mailman.post end it 'does not call notify_users' do - @mailman.should_not_receive(:notify_users) + expect(@mailman).not_to receive(:notify_users) @mailman.post end end @@ -204,15 +204,15 @@ describe Postzord::Dispatcher do @remote_people << alice.person @mailman = Postzord::Dispatcher.build(alice, @sm) @hydra = double() - Typhoeus::Hydra.stub(:new).and_return(@hydra) + allow(Typhoeus::Hydra).to receive(:new).and_return(@hydra) end it 'should queue an HttpMultiJob for the remote people' do - Postzord::Dispatcher::Public.any_instance.unstub(:deliver_to_remote) - Workers::HttpMulti.should_receive(:perform_async).with(alice.id, anything, @remote_people.map{|p| p.id}, anything).once + allow_any_instance_of(Postzord::Dispatcher::Public).to receive(:deliver_to_remote).and_call_original + expect(Workers::HttpMulti).to receive(:perform_async).with(alice.id, anything, @remote_people.map{|p| p.id}, anything).once @mailman.send(:deliver_to_remote, @remote_people) - Postzord::Dispatcher::Public.stub(:deliver_to_remote) + allow(Postzord::Dispatcher::Public).to receive(:deliver_to_remote) end end @@ -224,18 +224,18 @@ describe Postzord::Dispatcher do it 'queues a batch receive' do local_people = [] local_people << alice.person - Workers::ReceiveLocalBatch.should_receive(:perform_async).with(@sm.class.to_s, @sm.id, [alice.id]).once + expect(Workers::ReceiveLocalBatch).to receive(:perform_async).with(@sm.class.to_s, @sm.id, [alice.id]).once @mailman.send(:deliver_to_local, local_people) end it 'returns if people are empty' do - Workers::ReceiveLocalBatch.should_not_receive(:perform_async) + expect(Workers::ReceiveLocalBatch).not_to receive(:perform_async) @mailman.send(:deliver_to_local, []) end it 'returns if the object is a profile' do @mailman.instance_variable_set(:@object, Profile.new) - Workers::ReceiveLocalBatch.should_not_receive(:perform_async) + expect(Workers::ReceiveLocalBatch).not_to receive(:perform_async) @mailman.send(:deliver_to_local, [1]) end end @@ -243,28 +243,28 @@ describe Postzord::Dispatcher do describe '#object_should_be_processed_as_public?' do it 'returns true with a comment on a public post' do f = FactoryGirl.create(:comment, :post => FactoryGirl.build(:status_message, :public => true)) - Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be true + expect(Postzord::Dispatcher.object_should_be_processed_as_public?(f)).to be true end it 'returns false with a comment on a private post' do f = FactoryGirl.create(:comment, :post => FactoryGirl.build(:status_message, :public => false)) - Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be false + expect(Postzord::Dispatcher.object_should_be_processed_as_public?(f)).to be false end it 'returns true with a like on a comment on a public post' do f = FactoryGirl.create(:like, :target => FactoryGirl.build(:comment, :post => FactoryGirl.build(:status_message, :public => true))) - Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be true + expect(Postzord::Dispatcher.object_should_be_processed_as_public?(f)).to be true end it 'returns false with a like on a comment on a private post' do f = FactoryGirl.create(:like, :target => FactoryGirl.build(:comment, :post => FactoryGirl.build(:status_message, :public => false))) - Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be false + expect(Postzord::Dispatcher.object_should_be_processed_as_public?(f)).to be false end it 'returns false for a relayable_retraction' do f = RelayableRetraction.new f.target = FactoryGirl.create(:status_message, :public => true) - Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be false + expect(Postzord::Dispatcher.object_should_be_processed_as_public?(f)).to be false end end @@ -277,8 +277,8 @@ describe Postzord::Dispatcher do end it 'queues a job to notify the hub' do - Workers::PostToService.stub(:perform_async).with(anything, anything, anything) - Workers::PublishToHub.should_receive(:perform_async).with(alice.public_url) + allow(Workers::PostToService).to receive(:perform_async).with(anything, anything, anything) + expect(Workers::PublishToHub).to receive(:perform_async).with(alice.public_url) @zord.send(:deliver_to_services, nil, []) end @@ -286,7 +286,7 @@ describe Postzord::Dispatcher do @sm = FactoryGirl.create(:status_message) mailman = Postzord::Dispatcher.build(alice, @sm, :url => "http://joindiaspora.com/p/123") - mailman.should_not_receive(:deliver_to_hub) + expect(mailman).not_to receive(:deliver_to_hub) mailman.post end @@ -297,17 +297,17 @@ describe Postzord::Dispatcher do alice.services << @s2 mailman = Postzord::Dispatcher.build(alice, FactoryGirl.create(:status_message), :url => "http://joindiaspora.com/p/123", :services => [@s1]) - Workers::PublishToHub.stub(:perform_async).with(anything) - Workers::HttpMulti.stub(:perform_async).with(anything, anything, anything) - Workers::PostToService.should_receive(:perform_async).with(@s1.id, anything, anything) + allow(Workers::PublishToHub).to receive(:perform_async).with(anything) + allow(Workers::HttpMulti).to receive(:perform_async).with(anything, anything, anything) + expect(Workers::PostToService).to receive(:perform_async).with(@s1.id, anything, anything) mailman.post end it 'does not push to services if none are specified' do mailman = Postzord::Dispatcher.build(alice, FactoryGirl.create(:status_message), :url => "http://joindiaspora.com/p/123") - Workers::PublishToHub.stub(:perform_async).with(anything) - Workers::PostToService.should_not_receive(:perform_async).with(anything, anything, anything) + allow(Workers::PublishToHub).to receive(:perform_async).with(anything) + expect(Workers::PostToService).not_to receive(:perform_async).with(anything, anything, anything) mailman.post end @@ -315,7 +315,7 @@ describe Postzord::Dispatcher do retraction = SignedRetraction.build(alice, FactoryGirl.create(:status_message)) mailman = Postzord::Dispatcher.build(alice, retraction, :url => "http://joindiaspora.com/p/123", :services => [@service]) - Workers::DeletePostFromService.should_receive(:perform_async).with(anything, anything) + expect(Workers::DeletePostFromService).to receive(:perform_async).with(anything, anything) mailman.post end @@ -323,14 +323,14 @@ describe Postzord::Dispatcher do describe '#and_notify_local_users' do it 'calls notifiy_users' do - @zord.should_receive(:notify_users).with([bob]) + expect(@zord).to receive(:notify_users).with([bob]) @zord.send(:notify_local_users, [bob.person]) end end describe '#notify_users' do it 'enqueues a NotifyLocalUsers job' do - Workers::NotifyLocalUsers.should_receive(:perform_async).with([bob.id], @zord.object.class.to_s, @zord.object.id, @zord.object.author.id) + expect(Workers::NotifyLocalUsers).to receive(:perform_async).with([bob.id], @zord.object.class.to_s, @zord.object.id, @zord.object.author.id) @zord.send(:notify_users, [bob]) end end diff --git a/spec/lib/postzord/receiver/local_batch_spec.rb b/spec/lib/postzord/receiver/local_batch_spec.rb index ad1ef7115dfee3e8938b61556ac1b43f0837a91d..1a6c8e2fe61df12c768f46eb7224af28b8b4421d 100644 --- a/spec/lib/postzord/receiver/local_batch_spec.rb +++ b/spec/lib/postzord/receiver/local_batch_spec.rb @@ -11,31 +11,31 @@ describe Postzord::Receiver::LocalBatch do describe '.initialize' do it 'sets @post, @recipient_user_ids, and @user' do [:object, :recipient_user_ids, :users].each do |instance_var| - receiver.send(instance_var).should_not be_nil + expect(receiver.send(instance_var)).not_to be_nil end end end describe '#receive!' do it 'calls .create_share_visibilities' do - receiver.should_receive(:create_share_visibilities) + expect(receiver).to receive(:create_share_visibilities) receiver.receive! end it 'notifies mentioned users' do - receiver.should_receive(:notify_mentioned_users) + expect(receiver).to receive(:notify_mentioned_users) receiver.receive! end it 'notifies users' do - receiver.should_receive(:notify_users) + expect(receiver).to receive(:notify_users) receiver.receive! end end describe '#create_share_visibilities' do it 'calls sharevisibility.batch_import with hashes' do - ShareVisibility.should_receive(:batch_import).with(instance_of(Array), @object) + expect(ShareVisibility).to receive(:batch_import).with(instance_of(Array), @object) receiver.create_share_visibilities end end @@ -47,12 +47,12 @@ describe Postzord::Receiver::LocalBatch do :text => "Hey @{Bob; #{bob.diaspora_handle}}") receiver2 = Postzord::Receiver::LocalBatch.new(sm, @ids) - Notification.should_receive(:notify).with(bob, anything, alice.person) + expect(Notification).to receive(:notify).with(bob, anything, alice.person) receiver2.notify_mentioned_users end it 'does not call notify person for a non-mentioned person' do - Notification.should_not_receive(:notify) + expect(Notification).not_to receive(:notify) receiver.notify_mentioned_users end end @@ -60,7 +60,7 @@ describe Postzord::Receiver::LocalBatch do describe '#notify_users' do it 'calls notify for posts with notification type' do reshare = FactoryGirl.create(:reshare) - Notification.should_receive(:notify) + expect(Notification).to receive(:notify) receiver = Postzord::Receiver::LocalBatch.new(reshare, @ids) receiver.notify_users end @@ -68,7 +68,7 @@ describe Postzord::Receiver::LocalBatch do it 'calls notify for posts with notification type' do sm = FactoryGirl.create(:status_message, :author => alice.person) receiver = Postzord::Receiver::LocalBatch.new(sm, @ids) - Notification.should_not_receive(:notify) + expect(Notification).not_to receive(:notify) receiver.notify_users end end @@ -80,13 +80,13 @@ describe Postzord::Receiver::LocalBatch do end it 'calls notify_users' do - receiver.should_receive(:notify_users) + expect(receiver).to receive(:notify_users) receiver.perform! end it 'does not call create_visibilities and notify_mentioned_users' do - receiver.should_not_receive(:notify_mentioned_users) - receiver.should_not_receive(:create_share_visibilities) + expect(receiver).not_to receive(:notify_mentioned_users) + expect(receiver).not_to receive(:create_share_visibilities) receiver.perform! end end diff --git a/spec/lib/postzord/receiver/private_spec.rb b/spec/lib/postzord/receiver/private_spec.rb index 352c91d40c944396b7f31cbb2df715895f703457..645cc7d007f35a6f0d3845b8cb1860b06c7c3308 100644 --- a/spec/lib/postzord/receiver/private_spec.rb +++ b/spec/lib/postzord/receiver/private_spec.rb @@ -13,27 +13,27 @@ describe Postzord::Receiver::Private do describe '.initialize' do it 'valid for local' do - Webfinger.should_not_receive(:new) - Salmon::EncryptedSlap.should_not_receive(:from_xml) + expect(Webfinger).not_to receive(:new) + expect(Salmon::EncryptedSlap).not_to receive(:from_xml) zord = Postzord::Receiver::Private.new(bob, :person => alice.person, :object => @alices_post) - zord.instance_variable_get(:@user).should_not be_nil - zord.instance_variable_get(:@sender).should_not be_nil - zord.instance_variable_get(:@object).should_not be_nil + expect(zord.instance_variable_get(:@user)).not_to be_nil + expect(zord.instance_variable_get(:@sender)).not_to be_nil + expect(zord.instance_variable_get(:@object)).not_to be_nil end it 'valid for remote' do salmon_double = double() web_double = double() - web_double.should_receive(:fetch).and_return true - salmon_double.should_receive(:author_id).and_return(true) - Salmon::EncryptedSlap.should_receive(:from_xml).with(@salmon_xml, bob).and_return(salmon_double) - Webfinger.should_receive(:new).and_return(web_double) + expect(web_double).to receive(:fetch).and_return true + expect(salmon_double).to receive(:author_id).and_return(true) + expect(Salmon::EncryptedSlap).to receive(:from_xml).with(@salmon_xml, bob).and_return(salmon_double) + expect(Webfinger).to receive(:new).and_return(web_double) zord = Postzord::Receiver::Private.new(bob, :salmon_xml => @salmon_xml) - zord.instance_variable_get(:@user).should_not be_nil - zord.instance_variable_get(:@sender).should_not be_nil - zord.instance_variable_get(:@salmon_xml).should_not be_nil + expect(zord.instance_variable_get(:@user)).not_to be_nil + expect(zord.instance_variable_get(:@sender)).not_to be_nil + expect(zord.instance_variable_get(:@salmon_xml)).not_to be_nil end end @@ -46,24 +46,24 @@ describe Postzord::Receiver::Private do context 'returns false' do it 'if the salmon author does not exist' do @zord.instance_variable_set(:@sender, nil) - @zord.receive!.should == false + expect(@zord.receive!).to eq(false) end it 'if the author does not match the signature' do @zord.instance_variable_set(:@sender, FactoryGirl.create(:person)) - @zord.receive!.should == false + expect(@zord.receive!).to eq(false) end end context 'returns the sent object' do it 'returns the received object on success' do @zord.receive! - @zord.instance_variable_get(:@object).should respond_to(:to_diaspora_xml) + expect(@zord.instance_variable_get(:@object)).to respond_to(:to_diaspora_xml) end end it 'parses the salmon object' do - Diaspora::Parser.should_receive(:from_xml).with(@salmon.parsed_data).and_return(@alices_post) + expect(Diaspora::Parser).to receive(:from_xml).with(@salmon.parsed_data).and_return(@alices_post) @zord.receive! end end @@ -76,20 +76,20 @@ describe Postzord::Receiver::Private do it 'calls Notification.notify if object responds to notification_type' do cm = Comment.new - cm.stub(:receive).and_return(cm) + allow(cm).to receive(:receive).and_return(cm) - Notification.should_receive(:notify).with(bob, cm, alice.person) + expect(Notification).to receive(:notify).with(bob, cm, alice.person) zord = Postzord::Receiver::Private.new(bob, :person => alice.person, :object => cm) zord.receive_object end it 'does not call Notification.notify if object does not respond to notification_type' do - Notification.should_not_receive(:notify) + expect(Notification).not_to receive(:notify) @zord.receive_object end it 'calls receive on @object' do - obj = @zord.instance_variable_get(:@object).should_receive(:receive) + obj = expect(@zord.instance_variable_get(:@object)).to receive(:receive) @zord.receive_object end end diff --git a/spec/lib/postzord/receiver/public_spec.rb b/spec/lib/postzord/receiver/public_spec.rb index 45e44ba86fc0b22f8bc8c2accf61f9a4df797819..4507af4730ccda1ec4efcab154d8da77acb60213 100644 --- a/spec/lib/postzord/receiver/public_spec.rb +++ b/spec/lib/postzord/receiver/public_spec.rb @@ -31,7 +31,7 @@ describe Postzord::Receiver::Public do describe '#initialize' do it 'creates a Salmon instance variable' do receiver = Postzord::Receiver::Public.new(@xml) - receiver.salmon.should_not be_nil + expect(receiver.salmon).not_to be_nil end end @@ -41,28 +41,28 @@ describe Postzord::Receiver::Public do end it 'calls verify_signature' do - @receiver.should_receive(:verified_signature?) + expect(@receiver).to receive(:verified_signature?) @receiver.perform! end it 'returns false if signature is not verified' do - @receiver.should_receive(:verified_signature?).and_return(false) - @receiver.perform!.should be false + expect(@receiver).to receive(:verified_signature?).and_return(false) + expect(@receiver.perform!).to be false end context 'if signature is valid' do it 'calls recipient_user_ids' do - @receiver.should_receive(:recipient_user_ids) + expect(@receiver).to receive(:recipient_user_ids) @receiver.perform! end it 'saves the parsed object' do - @receiver.should_receive(:save_object) + expect(@receiver).to receive(:save_object) @receiver.perform! end - it 'enqueues a Workers::ReceiveLocalBatch' do - Workers::ReceiveLocalBatch.should_receive(:perform_async).with(anything, anything, anything) + it 'enqueues a Workers::ReceiveLocalBatch' do + expect(Workers::ReceiveLocalBatch).to receive(:perform_async).with(anything, anything, anything) @receiver.perform! end @@ -77,14 +77,14 @@ describe Postzord::Receiver::Public do describe '#verify_signature?' do it 'calls Slap#verified_for_key?' do receiver = Postzord::Receiver::Public.new(@xml) - receiver.salmon.should_receive(:verified_for_key?).with(instance_of(OpenSSL::PKey::RSA)) + expect(receiver.salmon).to receive(:verified_for_key?).with(instance_of(OpenSSL::PKey::RSA)) receiver.verified_signature? end end describe '#recipient_user_ids' do it 'calls User.all_sharing_with_person' do - User.should_receive(:all_sharing_with_person).and_return(double(:pluck => [])) + expect(User).to receive(:all_sharing_with_person).and_return(double(:pluck => [])) receiver = Postzord::Receiver::Public.new(@xml) receiver.perform! end @@ -104,7 +104,7 @@ describe Postzord::Receiver::Public do comment = double.as_null_object @receiver.instance_variable_set(:@object, comment) - comment.should_receive(:receive) + expect(comment).to receive(:receive) @receiver.receive_relayable end @@ -113,8 +113,8 @@ describe Postzord::Receiver::Public do @receiver.instance_variable_set(:@object, comment) local_batch_receiver = double.as_null_object - Postzord::Receiver::LocalBatch.stub(:new).and_return(local_batch_receiver) - local_batch_receiver.should_receive(:notify_users) + allow(Postzord::Receiver::LocalBatch).to receive(:new).and_return(local_batch_receiver) + expect(local_batch_receiver).to receive(:notify_users) @receiver.receive_relayable end end diff --git a/spec/lib/postzord/receiver_spec.rb b/spec/lib/postzord/receiver_spec.rb index 5ac6dbf9aa0925f59753dc195afe8e12c491bb80..a7dca6b1de34533face08437928e7fb65f54097f 100644 --- a/spec/lib/postzord/receiver_spec.rb +++ b/spec/lib/postzord/receiver_spec.rb @@ -11,11 +11,11 @@ describe Postzord::Receiver do describe "#perform!" do before do - @receiver.stub(:receive!).and_return(true) + allow(@receiver).to receive(:receive!).and_return(true) end it 'calls receive!' do - @receiver.should_receive(:receive!) + expect(@receiver).to receive(:receive!) @receiver.perform! end end diff --git a/spec/lib/publisher_spec.rb b/spec/lib/publisher_spec.rb index b83554ebf6d2866bd386696ba5f17fdab4bff060..7bb7a7c5d935a742dbd3de05367c6fe5e0824a33 100644 --- a/spec/lib/publisher_spec.rb +++ b/spec/lib/publisher_spec.rb @@ -8,29 +8,29 @@ describe Publisher do describe "#prefill" do it 'defaults to nothing' do - @publisher.prefill.should be_blank + expect(@publisher.prefill).to be_blank end it 'is settable' do - Publisher.new(alice, :prefill => "party!").prefill.should == "party!" + expect(Publisher.new(alice, :prefill => "party!").prefill).to eq("party!") end end describe '#text' do it 'is a formatted version of the prefill' do p = Publisher.new(alice, :prefill => "@{alice; alice@pod.com}") - p.text.should == "alice" + expect(p.text).to eq("alice") end end ["open", "public", "explain"].each do |property| describe "##{property}?" do it 'defaults to closed' do - @publisher.send("#{property}?".to_sym).should be_falsey + expect(@publisher.send("#{property}?".to_sym)).to be_falsey end it 'listens to the opts' do - Publisher.new(alice, {property.to_sym => true}).send("#{property}?".to_sym).should be true + expect(Publisher.new(alice, {property.to_sym => true}).send("#{property}?".to_sym)).to be true end end end diff --git a/spec/lib/pubsubhubbub_spec.rb b/spec/lib/pubsubhubbub_spec.rb index c486f0377e4000e200f178e82687b93841aaa02f..896e08279e6fcea0bd97aad98bd628250535ee3f 100644 --- a/spec/lib/pubsubhubbub_spec.rb +++ b/spec/lib/pubsubhubbub_spec.rb @@ -12,7 +12,7 @@ describe Pubsubhubbub do body = {'hub.url' => feed, 'hub.mode' => 'publish'} stub_request(:post, "http://hubzord.com/").to_return(:status => [202, 'you are awesome']) - Pubsubhubbub.new(hub).publish(feed).should be_success + expect(Pubsubhubbub.new(hub).publish(feed)).to be_success end end end diff --git a/spec/lib/rack/chrome_frame_spec.rb b/spec/lib/rack/chrome_frame_spec.rb index 965a56431feb2e157e714804308a170949c5eaf9..e3ae4a7147a906e76fc6bb38bc96d342628d409f 100644 --- a/spec/lib/rack/chrome_frame_spec.rb +++ b/spec/lib/rack/chrome_frame_spec.rb @@ -19,8 +19,8 @@ describe Rack::ChromeFrame do let(:ua_string) { "another browser chromeframe" } it "shouldn't complain about the browser" do - subject.body.should_not =~ /chrome=1/ - subject.body.should_not =~ /Diaspora doesn't support your version of Internet Explorer/ + expect(subject.body).not_to match(/chrome=1/) + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) end end @@ -28,8 +28,8 @@ describe Rack::ChromeFrame do let(:ua_string) { "MSIE 8" } it "shouldn't complain about the browser" do - subject.body.should_not =~ /chrome=1/ - subject.body.should_not =~ /Diaspora doesn't support your version of Internet Explorer/ + expect(subject.body).not_to match(/chrome=1/) + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) end end @@ -37,19 +37,19 @@ describe Rack::ChromeFrame do let(:ua_string) { "MSIE 7" } it "shouldn't complain about the browser" do - subject.body.should_not =~ /chrome=1/ - subject.body.should =~ /Diaspora doesn't support your version of Internet Explorer/ + expect(subject.body).not_to match(/chrome=1/) + expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) end - specify {@response.headers["Content-Length"].should == @response.body.length.to_s} + specify {expect(@response.headers["Content-Length"]).to eq(@response.body.length.to_s)} end context "any IE with chromeframe" do let(:ua_string) { "MSIE number chromeframe" } it "shouldn't complain about the browser" do - subject.body.should =~ /chrome=1/ - subject.body.should_not =~ /Diaspora doesn't support your version of Internet Explorer/ + expect(subject.body).to match(/chrome=1/) + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) end - specify {@response.headers["Content-Length"].should == @response.body.length.to_s} + specify {expect(@response.headers["Content-Length"]).to eq(@response.body.length.to_s)} end end diff --git a/spec/lib/rake_helper_spec.rb b/spec/lib/rake_helper_spec.rb index 1f8001fbdb5749cb388e1311d908e3093a3bd9ec..1bc16079a9cf1134b1b488dee531fb1a5ace40c2 100644 --- a/spec/lib/rake_helper_spec.rb +++ b/spec/lib/rake_helper_spec.rb @@ -23,7 +23,7 @@ describe RakeHelpers do it 'should send emails to each email' do - EmailInviter.should_receive(:new).exactly(3).times.and_return(double.as_null_object) + expect(EmailInviter).to receive(:new).exactly(3).times.and_return(double.as_null_object) process_emails(@csv, 100, 1, false) end end diff --git a/spec/lib/salmon/encrypted_slap_spec.rb b/spec/lib/salmon/encrypted_slap_spec.rb index 90ed786a752d655dcbb379567ec683dd73cb8aa9..ba297edcfe03dd5eb28e5a36c484776f37b50985 100644 --- a/spec/lib/salmon/encrypted_slap_spec.rb +++ b/spec/lib/salmon/encrypted_slap_spec.rb @@ -14,12 +14,12 @@ describe Salmon::EncryptedSlap do it 'makes the data in the signature encrypted with that key' do key_hash = {'key' => @created_salmon.aes_key, 'iv' => @created_salmon.iv} decoded_string = Salmon::EncryptedSlap.decode64url(@created_salmon.magic_sig.data) - alice.aes_decrypt(decoded_string, key_hash).should == @post.to_diaspora_xml + expect(alice.aes_decrypt(decoded_string, key_hash)).to eq(@post.to_diaspora_xml) end it 'sets aes and iv key' do - @created_salmon.aes_key.should_not be_nil - @created_salmon.iv.should_not be_nil + expect(@created_salmon.aes_key).not_to be_nil + expect(@created_salmon.iv).not_to be_nil end end @@ -30,15 +30,15 @@ describe Salmon::EncryptedSlap do end it 'sets the author id' do - @new_slap.author_id.should == alice.diaspora_handle + expect(@new_slap.author_id).to eq(alice.diaspora_handle) end it 'sets the aes_key' do - @new_slap.aes_key.should == @created_salmon.aes_key + expect(@new_slap.aes_key).to eq(@created_salmon.aes_key) end it 'sets the aes_key' do - @new_slap.iv.should == @created_salmon.iv + expect(@new_slap.iv).to eq(@created_salmon.iv) end end @@ -47,15 +47,15 @@ describe Salmon::EncryptedSlap do let(:parsed_salmon) { Salmon::EncryptedSlap.from_xml(xml, alice)} it 'should parse out the aes key' do - parsed_salmon.aes_key.should == @created_salmon.aes_key + expect(parsed_salmon.aes_key).to eq(@created_salmon.aes_key) end it 'should parse out the iv' do - parsed_salmon.iv.should == @created_salmon.iv + expect(parsed_salmon.iv).to eq(@created_salmon.iv) end it 'contains the original data' do - parsed_salmon.parsed_data.should == @post.to_diaspora_xml + expect(parsed_salmon.parsed_data).to eq(@post.to_diaspora_xml) end end @@ -66,7 +66,7 @@ describe Salmon::EncryptedSlap do it 'has a encrypted header field' do doc = Nokogiri::XML(@xml) - doc.find("encrypted_header").should_not be_blank + expect(doc.find("encrypted_header")).not_to be_blank end context "encrypted header" do @@ -77,15 +77,15 @@ describe Salmon::EncryptedSlap do end it 'contains the aes key' do - @dh_doc.search('aes_key').map(&:text).should == [@created_salmon.aes_key] + expect(@dh_doc.search('aes_key').map(&:text)).to eq([@created_salmon.aes_key]) end it 'contains the initialization vector' do - @dh_doc.search('iv').map(&:text).should == [@created_salmon.iv] + expect(@dh_doc.search('iv').map(&:text)).to eq([@created_salmon.iv]) end it 'contains the author id' do - @dh_doc.search('author_id').map(&:text).should == [alice.diaspora_handle] + expect(@dh_doc.search('author_id').map(&:text)).to eq([alice.diaspora_handle]) end end end diff --git a/spec/lib/salmon/slap_spec.rb b/spec/lib/salmon/slap_spec.rb index 32da4e720581bd4d445fb376d93a838bba8ecc88..d3a6851af82ccf0927c81296c699be14d149822f 100644 --- a/spec/lib/salmon/slap_spec.rb +++ b/spec/lib/salmon/slap_spec.rb @@ -8,11 +8,11 @@ describe Salmon::Slap do describe '#create' do it 'has data in the magic envelope' do - @created_salmon.magic_sig.data.should_not be nil + expect(@created_salmon.magic_sig.data).not_to be nil end it 'has no parsed_data' do - @created_salmon.parsed_data.should be nil + expect(@created_salmon.parsed_data).to be nil end end @@ -20,13 +20,13 @@ describe Salmon::Slap do it 'works' do salmon_string = @created_salmon.xml_for(nil) salmon = Salmon::Slap.from_xml(salmon_string) - salmon.author.should == alice.person - salmon.parsed_data.should == @post.to_diaspora_xml + expect(salmon.author).to eq(alice.person) + expect(salmon.parsed_data).to eq(@post.to_diaspora_xml) end describe '#from_xml' do it 'procsses the header' do - Salmon::Slap.any_instance.should_receive(:process_header) + expect_any_instance_of(Salmon::Slap).to receive(:process_header) Salmon::Slap.from_xml(@created_salmon.xml_for(eve.person)) end end @@ -35,7 +35,7 @@ describe Salmon::Slap do it 'sets the author id' do slap = Salmon::Slap.new slap.process_header(Nokogiri::XML(@created_salmon.plaintext_header)) - slap.author_id.should == alice.diaspora_handle + expect(slap.author_id).to eq(alice.diaspora_handle) end end @@ -44,7 +44,7 @@ describe Salmon::Slap do let(:parsed_salmon) { Salmon::Slap.from_xml(xml, alice)} it 'should reference a local author' do - parsed_salmon.author.should == alice.person + expect(parsed_salmon.author).to eq(alice.person) end it 'should fail if no author is found' do @@ -60,19 +60,19 @@ describe Salmon::Slap do let(:parsed_salmon) { Salmon::Slap.from_xml(xml)} it 'should parse out the authors diaspora_handle' do - parsed_salmon.author_id.should == alice.person.diaspora_handle + expect(parsed_salmon.author_id).to eq(alice.person.diaspora_handle) end it 'verifies the signature for the sender' do - parsed_salmon.verified_for_key?(alice.public_key).should be true + expect(parsed_salmon.verified_for_key?(alice.public_key)).to be true end it 'verifies the signature for the sender' do - parsed_salmon.verified_for_key?(FactoryGirl.create(:person).public_key).should be false + expect(parsed_salmon.verified_for_key?(FactoryGirl.create(:person).public_key)).to be false end it 'contains the original data' do - parsed_salmon.parsed_data.should == @post.to_diaspora_xml + expect(parsed_salmon.parsed_data).to eq(@post.to_diaspora_xml) end end @@ -83,12 +83,12 @@ describe Salmon::Slap do it "has diaspora as the root" do doc = Nokogiri::XML(@xml) - doc.root.name.should == "diaspora" + expect(doc.root.name).to eq("diaspora") end it "it has the descrypted header" do doc = Nokogiri::XML(@xml) - doc.search("header").should_not be_blank + expect(doc.search("header")).not_to be_blank end context "header" do @@ -96,14 +96,14 @@ describe Salmon::Slap do it "it has author_id node " do doc = Nokogiri::XML(@xml) search = doc.search("header").search("author_id") - search.map(&:text).should == [alice.diaspora_handle] + expect(search.map(&:text)).to eq([alice.diaspora_handle]) end end it "it has the magic envelope " do doc = Nokogiri::XML(@xml) - doc.find("/me:env").should_not be_blank + expect(doc.find("/me:env")).not_to be_blank end end end diff --git a/spec/lib/statistics_spec.rb b/spec/lib/statistics_spec.rb index 6ce40e5e3a0aa4bce342ad809d47980e7b3eda42..93a98d9a3e53f6ffc127ddc55720086a4bad77cd 100644 --- a/spec/lib/statistics_spec.rb +++ b/spec/lib/statistics_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' describe Statistics do def result_should_equal( actual ) - actual.count.should == @result.count + expect(actual.count).to eq(@result.count) @result.each do |expected_hash| - actual.find { |actual_hash| + expect(actual.find { |actual_hash| actual_hash['id'].to_i == expected_hash['id'].to_i && actual_hash['count'].to_i == expected_hash['count'].to_i - }.should_not be_nil + }).not_to be_nil end end @@ -98,7 +98,7 @@ describe Statistics do {"id" => local_luke.id , "count" => 0, "connected" => 0 }, {"id" => local_leia.id , "count" => 0, "connected" => 0 }] - @stats.fb_connected_distribution.should =~ @result + expect(@stats.fb_connected_distribution).to match_array(@result) end end @@ -106,15 +106,15 @@ describe Statistics do "mentions_count", "sign_in_count", "contacts_sharing_with_count" ].each do |method| it "#{method}_sql calls where_sql" do - @stats.should_receive(:where_clause_sql) + expect(@stats).to receive(:where_clause_sql) @stats.send("#{method}_sql".to_sym) end if !["sign_in_count", "tags_followed_count"].include?(method) it "#generate_correlations calls correlate with #{method} and sign_in_count" do - @stats.stub(:correlate).and_return(0.5) - @stats.should_receive(:correlate).with(method.to_sym,:sign_in_count).and_return(0.75) + allow(@stats).to receive(:correlate).and_return(0.5) + expect(@stats).to receive(:correlate).with(method.to_sym,:sign_in_count).and_return(0.75) @stats.generate_correlations end end @@ -123,8 +123,8 @@ describe Statistics do describe "#correlation" do it 'returns the correlation coefficient' do - @stats.correlation([1,2],[1,2]).to_s.should == 1.0.to_s - @stats.correlation([1,2,1,2],[1,1,2,2]).to_s.should == 0.0.to_s + expect(@stats.correlation([1,2],[1,2]).to_s).to eq(1.0.to_s) + expect(@stats.correlation([1,2,1,2],[1,1,2,2]).to_s).to eq(0.0.to_s) end end describe "#generate_correlations" do @@ -133,21 +133,21 @@ describe Statistics do bob.post(:status_message, :text => "here is a message") bob.save! - c = @stats.generate_correlations[:posts_count].round(1).should == 1.0 + c = expect(@stats.generate_correlations[:posts_count].round(1)).to eq(1.0) end end describe "#correlate" do it 'calls correlation with post' do - User.connection.should_receive(:select_all).and_return([{"id"=> 1, "count" => 7}, + expect(User.connection).to receive(:select_all).and_return([{"id"=> 1, "count" => 7}, {"id" => 2, "count" => 8}, {"id" => 3, "count" => 9}], [{"id"=> 1, "count" => 17}, {"id" => 3, "count" => 19}] ) - @stats.should_receive(:correlation).with([7,9],[17,19]).and_return(0.5) - @stats.correlate(:posts_count,:sign_in_count).should == 0.5 + expect(@stats).to receive(:correlation).with([7,9],[17,19]).and_return(0.5) + expect(@stats.correlate(:posts_count,:sign_in_count)).to eq(0.5) end end diff --git a/spec/lib/stream/aspect_spec.rb b/spec/lib/stream/aspect_spec.rb index 1ec82d1bd9e2f010afb8661b6ffccd8b6272329a..96c8ce7c4fd0d7cca4659a97109a53c095152742 100644 --- a/spec/lib/stream/aspect_spec.rb +++ b/spec/lib/stream/aspect_spec.rb @@ -10,7 +10,7 @@ describe Stream::Aspect do alice = double.as_null_object stream = Stream::Aspect.new(alice, [1,2,3]) - alice.aspects.should_receive(:where) + expect(alice.aspects).to receive(:where) stream.aspects end @@ -18,16 +18,16 @@ describe Stream::Aspect do alice = double.as_null_object stream = Stream::Aspect.new(alice, []) - alice.aspects.should_not_receive(:where) + expect(alice.aspects).not_to receive(:where) stream.aspects end it 'filters aspects given a user' do alice = double(:aspects => [double(:id => 1)]) - alice.aspects.stub(:where).and_return(alice.aspects) + allow(alice.aspects).to receive(:where).and_return(alice.aspects) stream = Stream::Aspect.new(alice, [1,2,3]) - stream.aspects.should == alice.aspects + expect(stream.aspects).to eq(alice.aspects) end end @@ -38,8 +38,8 @@ describe Stream::Aspect do stream = Stream::Aspect.new(alice, [1,2]) - stream.should_receive(:aspects).and_return(aspects) - aspects.should_receive(:map) + expect(stream).to receive(:aspects).and_return(aspects) + expect(aspects).to receive(:map) stream.aspect_ids end end @@ -52,33 +52,33 @@ describe Stream::Aspect do it 'calls visible posts for the given user' do stream = Stream::Aspect.new(@alice, [1,2]) - @alice.should_receive(:visible_shareables).and_return(double.as_null_object) + expect(@alice).to receive(:visible_shareables).and_return(double.as_null_object) stream.posts end it 'is called with 2 types' do stream = Stream::Aspect.new(@alice, [1,2], :order => 'created_at') - @alice.should_receive(:visible_shareables).with(Post, hash_including(:type=> ['StatusMessage', 'Reshare'])).and_return(double.as_null_object) + expect(@alice).to receive(:visible_shareables).with(Post, hash_including(:type=> ['StatusMessage', 'Reshare'])).and_return(double.as_null_object) stream.posts end it 'respects ordering' do stream = Stream::Aspect.new(@alice, [1,2], :order => 'created_at') - @alice.should_receive(:visible_shareables).with(Post, hash_including(:order => 'created_at DESC')).and_return(double.as_null_object) + expect(@alice).to receive(:visible_shareables).with(Post, hash_including(:order => 'created_at DESC')).and_return(double.as_null_object) stream.posts end it 'respects max_time' do stream = Stream::Aspect.new(@alice, [1,2], :max_time => 123) - @alice.should_receive(:visible_shareables).with(Post, hash_including(:max_time => instance_of(Time))).and_return(double.as_null_object) + expect(@alice).to receive(:visible_shareables).with(Post, hash_including(:max_time => instance_of(Time))).and_return(double.as_null_object) stream.posts end it 'passes for_all_aspects to visible posts' do stream = Stream::Aspect.new(@alice, [1,2], :max_time => 123) all_aspects = double - stream.stub(:for_all_aspects?).and_return(all_aspects) - @alice.should_receive(:visible_shareables).with(Post, hash_including(:all_aspects? => all_aspects)).and_return(double.as_null_object) + allow(stream).to receive(:for_all_aspects?).and_return(all_aspects) + expect(@alice).to receive(:visible_shareables).with(Post, hash_including(:all_aspects? => all_aspects)).and_return(double.as_null_object) stream.posts end end @@ -91,8 +91,8 @@ describe Stream::Aspect do aspect_ids = [1,2,3] stream = Stream::Aspect.new(alice, []) - stream.stub(:aspect_ids).and_return(aspect_ids) - Person.should_receive(:unique_from_aspects).with(stream.aspect_ids, alice).and_return(double(:includes => :profile)) + allow(stream).to receive(:aspect_ids).and_return(aspect_ids) + expect(Person).to receive(:unique_from_aspects).with(stream.aspect_ids, alice).and_return(double(:includes => :profile)) stream.people end end @@ -104,31 +104,31 @@ describe Stream::Aspect do end it "returns an aspect if the stream is not for all the user's aspects" do - @stream.stub(:for_all_aspects?).and_return(false) - @stream.aspect.should_not be_nil + allow(@stream).to receive(:for_all_aspects?).and_return(false) + expect(@stream.aspect).not_to be_nil end it "returns nothing if the stream is not for all the user's aspects" do - @stream.stub(:for_all_aspects?).and_return(true) - @stream.aspect.should be_nil + allow(@stream).to receive(:for_all_aspects?).and_return(true) + expect(@stream.aspect).to be_nil end end describe 'for_all_aspects?' do before do alice = double.as_null_object - alice.aspects.stub(:size).and_return(2) + allow(alice.aspects).to receive(:size).and_return(2) @stream = Stream::Aspect.new(alice, [1,2]) end it "is true if the count of aspect_ids is equal to the size of the user's aspect count" do - @stream.aspect_ids.stub(:length).and_return(2) - @stream.should be_for_all_aspects + allow(@stream.aspect_ids).to receive(:length).and_return(2) + expect(@stream).to be_for_all_aspects end it "is false if the count of aspect_ids is not equal to the size of the user's aspect count" do - @stream.aspect_ids.stub(:length).and_return(1) - @stream.should_not be_for_all_aspects + allow(@stream.aspect_ids).to receive(:length).and_return(1) + expect(@stream).not_to be_for_all_aspects end end diff --git a/spec/lib/stream/base_spec.rb b/spec/lib/stream/base_spec.rb index 09f2cf6bb962097f4c9785892c26d5b7181347a8..2f5c2435e1af06250915dcc9f98b8abc1b257fe4 100644 --- a/spec/lib/stream/base_spec.rb +++ b/spec/lib/stream/base_spec.rb @@ -8,17 +8,17 @@ describe Stream::Base do describe '#contacts_link' do it 'should default to your contacts page' do - @stream.contacts_link.should =~ /contacts/ + expect(@stream.contacts_link).to match(/contacts/) end end describe '#stream_posts' do it "should returns the posts.for_a_stream" do posts = double - @stream.stub(:posts).and_return(posts) - @stream.stub(:like_posts_for_stream!) + allow(@stream).to receive(:posts).and_return(posts) + allow(@stream).to receive(:like_posts_for_stream!) - posts.should_receive(:for_a_stream).with(anything, anything, alice).and_return(posts) + expect(posts).to receive(:for_a_stream).with(anything, anything, alice).and_return(posts) @stream.stream_posts end @@ -30,7 +30,7 @@ describe Stream::Base do end it "marks the posts as liked" do - @stream.stream_posts.first.user_like.id.should == @like.id + expect(@stream.stream_posts.first.user_like.id).to eq(@like.id) end end end @@ -38,39 +38,39 @@ describe Stream::Base do describe '.can_comment?' do before do @person = FactoryGirl.create(:person) - @stream.stub(:people).and_return([bob.person, eve.person, @person]) + allow(@stream).to receive(:people).and_return([bob.person, eve.person, @person]) end it 'allows me to comment on my local contacts post' do post = FactoryGirl.create(:status_message, :author => bob.person) - @stream.can_comment?(post).should be true + expect(@stream.can_comment?(post)).to be true end it 'allows me to comment on my own post' do post = FactoryGirl.create(:status_message, :author => alice.person) - @stream.can_comment?(post).should be true + expect(@stream.can_comment?(post)).to be true end it 'allows me to comment on any local public post' do post = FactoryGirl.create(:status_message, :author => eve.person) - @stream.can_comment?(post).should be true + expect(@stream.can_comment?(post)).to be true end it 'allows me to comment on a remote contacts post' do Contact.create!(:user => @stream.user, :person => @person) post = FactoryGirl.create(:status_message, :author => @person) - @stream.can_comment?(post).should be true + expect(@stream.can_comment?(post)).to be true end it 'returns false if person is remote and not a contact' do post = FactoryGirl.create(:status_message, :author => @person) - @stream.can_comment?(post).should be false + expect(@stream.can_comment?(post)).to be false end end describe '#people' do it 'excludes blocked people' do - @stream.should_receive(:stream_posts).and_return(double.as_null_object) + expect(@stream).to receive(:stream_posts).and_return(double.as_null_object) @stream.people end end diff --git a/spec/lib/stream/followed_tag_spec.rb b/spec/lib/stream/followed_tag_spec.rb index 832847d3277e8b082d8acb35c1dabf9665ec6e01..f46d49a7051292142aef68112976b7fb6db49296 100644 --- a/spec/lib/stream/followed_tag_spec.rb +++ b/spec/lib/stream/followed_tag_spec.rb @@ -4,7 +4,7 @@ require Rails.root.join('spec', 'shared_behaviors', 'stream') describe Stream::FollowedTag do before do @stream = Stream::FollowedTag.new(alice, :max_time => Time.now, :order => 'updated_at') - @stream.stub(:tag_string).and_return("foo") + allow(@stream).to receive(:tag_string).and_return("foo") end describe 'shared behaviors' do diff --git a/spec/lib/stream/multi_spec.rb b/spec/lib/stream/multi_spec.rb index a0a8336083a4cc7fe4f4f3ca7816dfe2d549a42e..2f77fc180ddcc5061c621b6d8bf7853f87b8fea9 100644 --- a/spec/lib/stream/multi_spec.rb +++ b/spec/lib/stream/multi_spec.rb @@ -12,11 +12,11 @@ describe Stream::Multi do describe "#posts" do it "calls EvilQuery::MultiStream with correct parameters" do - ::EvilQuery::MultiStream.should_receive(:new) + expect(::EvilQuery::MultiStream).to receive(:new) .with(alice, 'updated_at', @stream.max_time, AppConfig.settings.community_spotlight.enable? && alice.show_community_spotlight_in_stream?) - .and_return(double.tap { |m| m.stub(:make_relation!)}) + .and_return(double.tap { |m| allow(m).to receive(:make_relation!)}) @stream.posts end end @@ -24,17 +24,17 @@ describe Stream::Multi do describe '#publisher_opts' do it 'prefills, sets public, and autoexpands if welcome? is set' do prefill_text = "sup?" - @stream.stub(:welcome?).and_return(true) - @stream.stub(:publisher_prefill).and_return(prefill_text) - @stream.send(:publisher_opts).should == {:open => true, + allow(@stream).to receive(:welcome?).and_return(true) + allow(@stream).to receive(:publisher_prefill).and_return(prefill_text) + expect(@stream.send(:publisher_opts)).to eq({:open => true, :prefill => prefill_text, - :public => true} + :public => true}) end it 'provides no opts if welcome? is not set' do prefill_text = "sup?" - @stream.stub(:welcome?).and_return(false) - @stream.send(:publisher_opts).should == {} + allow(@stream).to receive(:welcome?).and_return(false) + expect(@stream.send(:publisher_opts)).to eq({}) end end @@ -47,11 +47,11 @@ describe Stream::Multi do end it 'returns includes new user hashtag' do - @stream.send(:publisher_prefill).should match(/#NewHere/i) + expect(@stream.send(:publisher_prefill)).to match(/#NewHere/i) end it 'includes followed hashtags' do - @stream.send(:publisher_prefill).should include("#cats") + expect(@stream.send(:publisher_prefill)).to include("#cats") end context 'when invited by another user' do @@ -64,7 +64,7 @@ describe Stream::Multi do it 'includes a mention of the inviter' do mention = "@{#{@inviter.name} ; #{@inviter.diaspora_handle}}" - @stream.send(:publisher_prefill).should include(mention) + expect(@stream.send(:publisher_prefill)).to include(mention) end end end @@ -76,12 +76,12 @@ describe Stream::Multi do it 'returns true if user is getting started' do alice.getting_started = true - @stream.send(:welcome?).should be true + expect(@stream.send(:welcome?)).to be true end it 'returns false if user is getting started' do alice.getting_started = false - @stream.send(:welcome?).should be false + expect(@stream.send(:welcome?)).to be false end end end diff --git a/spec/lib/stream/person_spec.rb b/spec/lib/stream/person_spec.rb index 8f8ecdc735fce2b41ce007e0e621f2d727f7f533..f5eb10224dda98d8c752b1ab028a8a6df8104caa 100644 --- a/spec/lib/stream/person_spec.rb +++ b/spec/lib/stream/person_spec.rb @@ -28,7 +28,7 @@ describe Stream::Person do posts = posts.reverse.slice(0..14) fetched_posts = fetched_posts.slice(0..14) - fetched_posts.should == posts + expect(fetched_posts).to eq(posts) end end diff --git a/spec/lib/stream/tag_spec.rb b/spec/lib/stream/tag_spec.rb index e82e59ad4d6e955c076e45e5b04d715caaca03c7..ea74fec6279e580ce029155fd9c63559278b4544 100644 --- a/spec/lib/stream/tag_spec.rb +++ b/spec/lib/stream/tag_spec.rb @@ -14,30 +14,30 @@ describe Stream::Tag do it 'displays your own post' do my_post = alice.post(:status_message, :text => "#what", :to => 'all') - @stream.posts.should == [my_post] + expect(@stream.posts).to eq([my_post]) end it "displays a friend's post" do other_post = bob.post(:status_message, :text => "#what", :to => 'all') - @stream.posts.should == [other_post] + expect(@stream.posts).to eq([other_post]) end it 'displays a public post' do other_post = eve.post(:status_message, :text => "#what", :public => true, :to => 'all') - @stream.posts.should == [other_post] + expect(@stream.posts).to eq([other_post]) end it 'displays a public post that was sent to no one' do stranger = FactoryGirl.create(:user_with_aspect) stranger_post = stranger.post(:status_message, :text => "#what", :public => true, :to => 'all') - @stream.posts.should == [stranger_post] + expect(@stream.posts).to eq([stranger_post]) end it 'displays a post with a comment containing the tag search' do skip "this code is way too slow. need to re-implement in a way that doesn't suck" other_post = bob.post(:status_message, :text => "sup y'all", :to => 'all') FactoryGirl.create(:comment, :text => "#what", :post => other_post) - @stream.posts.should == [other_post] + expect(@stream.posts).to eq([other_post]) end end @@ -50,7 +50,7 @@ describe Stream::Tag do it "displays only public posts with the tag" do stream = Stream::Tag.new(nil, "what") - stream.posts.should == [@post] + expect(stream.posts).to eq([@post]) end end @@ -58,7 +58,7 @@ describe Stream::Tag do it "assigns the set of people who authored a post containing the tag" do alice.post(:status_message, :text => "#what", :public => true, :to => 'all') stream = Stream::Tag.new(nil, "what") - stream.people.should == [alice.person] + expect(stream.people).to eq([alice.person]) end end @@ -68,7 +68,7 @@ describe Stream::Tag do alice.profile.tag_string = "#whatevs" alice.profile.build_tags alice.profile.save! - stream.tagged_people.should == [alice.person] + expect(stream.tagged_people).to eq([alice.person]) end end @@ -81,7 +81,7 @@ describe Stream::Tag do it 'returns posts regardless of the tag case' do stream = Stream::Tag.new(nil, "newhere") - stream.posts.should =~ [@post_lc, @post_uc, @post_cp] + expect(stream.posts).to match_array([@post_lc, @post_uc, @post_cp]) end end @@ -95,18 +95,18 @@ describe Stream::Tag do describe '#tag_name=' do it 'downcases the tag' do stream = Stream::Tag.new(nil, "WHAT") - stream.tag_name.should == 'what' + expect(stream.tag_name).to eq('what') end it 'removes #es' do stream = Stream::Tag.new(nil, "#WHAT") - stream.tag_name.should == 'what' + expect(stream.tag_name).to eq('what') end end describe "#publisher" do it 'creates a publisher with the tag prefill' do - Publisher.should_receive(:new).with(anything(), anything) + expect(Publisher).to receive(:new).with(anything(), anything) @stream = Stream::Tag.new(alice, "what") end end diff --git a/spec/lib/webfinger_profile_spec.rb b/spec/lib/webfinger_profile_spec.rb index aa42d2d648bd24512acbb380f3c40d8816e287d2..51991f084589802449ab3b17961a67455bba33fb 100644 --- a/spec/lib/webfinger_profile_spec.rb +++ b/spec/lib/webfinger_profile_spec.rb @@ -11,22 +11,22 @@ describe WebfingerProfile do describe '#valid_diaspora_profile?' do it 'should check all of the required fields' do - manual_nil_check(profile).should == profile.valid_diaspora_profile? + expect(manual_nil_check(profile)).to eq(profile.valid_diaspora_profile?) end end describe '#set_fields' do it 'should check to make sure it has a the right webfinger profile' do - proc{ WebfingerProfile.new("nottom@tom.joindiaspora.com", webfinger_profile)}.should raise_error + expect{ WebfingerProfile.new("nottom@tom.joindiaspora.com", webfinger_profile)}.to raise_error end it 'should handle a non-diaspora profile without blowing up' do - proc{ WebfingerProfile.new("evan@status.net", not_diaspora_webfinger)}.should_not raise_error + expect{ WebfingerProfile.new("evan@status.net", not_diaspora_webfinger)}.not_to raise_error end [:links, :hcard, :guid, :seed_location, :public_key].each do |field| it 'should sets the #{field} field' do - profile.send(field).should be_present + expect(profile.send(field)).to be_present end end end diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index ad1d667d5e328286a36c4b77d0f9d2eedf65de20..25104bb379c307cb18977754a38bbaccec736949 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -16,23 +16,23 @@ describe Webfinger do describe '#intialize' do it 'sets account ' do n = Webfinger.new("mbs348@gmail.com") - n.account.should_not be nil + expect(n.account).not_to be nil end it "downcases account and strips whitespace, and gsub 'acct:'" do n = Webfinger.new("acct:BIGBOY@Example.Org ") - n.account.should == 'bigboy@example.org' + expect(n.account).to eq('bigboy@example.org') end it 'should set ssl as the default' do foo = Webfinger.new(account) - foo.ssl.should be true + expect(foo.ssl).to be true end end describe '.in_background' do it 'enqueues a Workers::FetchWebfinger job' do - Workers::FetchWebfinger.should_receive(:perform_async).with(account) + expect(Workers::FetchWebfinger).to receive(:perform_async).with(account) Webfinger.in_background(account) end end @@ -40,12 +40,12 @@ describe Webfinger do describe '#fetch' do it 'works' do finger = Webfinger.new(account_in_fixtures) - finger.stub(:host_meta_xrd).and_return(host_meta_xrd) - finger.stub(:hcard_xrd).and_return(hcard_xml) - finger.stub(:webfinger_profile_xrd).and_return(webfinger_xrd) + allow(finger).to receive(:host_meta_xrd).and_return(host_meta_xrd) + allow(finger).to receive(:hcard_xrd).and_return(hcard_xml) + allow(finger).to receive(:webfinger_profile_xrd).and_return(webfinger_xrd) person = finger.fetch - person.should be_valid - person.should be_a Person + expect(person).to be_valid + expect(person).to be_a Person end end @@ -56,7 +56,7 @@ describe Webfinger do stub_request(:get, url). to_return(:status => 200, :body => host_meta_xrd) - finger.get(url).should == host_meta_xrd + expect(finger.get(url)).to eq(host_meta_xrd) end it 'follows redirects' do @@ -70,7 +70,7 @@ describe Webfinger do finger.host_meta_xrd - a_request(:get, redirect_url).should have_been_made + expect(a_request(:get, redirect_url)).to have_been_made end it 'returns false on 404' do @@ -78,36 +78,36 @@ describe Webfinger do stub_request(:get, url). to_return(:status => 404, :body => nil) - finger.get(url).should_not == nil - finger.get(url).should == false + expect(finger.get(url)).not_to eq(nil) + expect(finger.get(url)).to eq(false) end end describe 'existing_person_with_profile?' do it 'returns true if cached_person is present and has a profile' do - finger.should_receive(:cached_person).twice.and_return(FactoryGirl.create(:person)) - finger.existing_person_with_profile?.should be true + expect(finger).to receive(:cached_person).twice.and_return(FactoryGirl.create(:person)) + expect(finger.existing_person_with_profile?).to be true end it 'returns false if it has no person' do - finger.stub(:cached_person).and_return false - finger.existing_person_with_profile?.should be false + allow(finger).to receive(:cached_person).and_return false + expect(finger.existing_person_with_profile?).to be false end it 'returns false if the person has no profile' do p = FactoryGirl.create(:person) p.profile = nil - finger.stub(:cached_person).and_return(p) - finger.existing_person_with_profile?.should be false + allow(finger).to receive(:cached_person).and_return(p) + expect(finger.existing_person_with_profile?).to be false end end describe 'cached_person' do it 'sets the person by looking up the account from Person.by_account_identifier' do person = double - Person.should_receive(:by_account_identifier).with(account).and_return(person) - finger.cached_person.should == person - finger.person.should == person + expect(Person).to receive(:by_account_identifier).with(account).and_return(person) + expect(finger.cached_person).to eq(person) + expect(finger.person).to eq(person) end end @@ -116,16 +116,16 @@ describe Webfinger do context 'with a cached_person' do it 'calls Person#assign_new_profile_from_hcard with the fetched hcard' do finger.hcard_xrd = hcard_xml - finger.stub(:person).and_return(bob.person) - bob.person.should_receive(:assign_new_profile_from_hcard).with(finger.hcard) + allow(finger).to receive(:person).and_return(bob.person) + expect(bob.person).to receive(:assign_new_profile_from_hcard).with(finger.hcard) finger.create_or_update_person_from_webfinger_profile! end end context 'with no cached person' do it 'sets person based on make_person_from_webfinger' do - finger.stub(:person).and_return(nil) - finger.should_receive(:make_person_from_webfinger) + allow(finger).to receive(:person).and_return(nil) + expect(finger).to receive(:make_person_from_webfinger) finger.create_or_update_person_from_webfinger_profile! end end @@ -133,67 +133,67 @@ describe Webfinger do describe '#host_meta_xrd' do it 'calls #get with host_meta_url' do - finger.stub(:host_meta_url).and_return('meta') - finger.should_receive(:get).with('meta') + allow(finger).to receive(:host_meta_url).and_return('meta') + expect(finger).to receive(:get).with('meta') finger.host_meta_xrd end it 'should retry with ssl off a second time' do - finger.should_receive(:get).and_raise(StandardError) - finger.should_receive(:get) + expect(finger).to receive(:get).and_raise(StandardError) + expect(finger).to receive(:get) finger.host_meta_xrd - finger.ssl.should be false + expect(finger.ssl).to be false end end describe '#hcard' do it 'calls HCard.build' do - finger.stub(:hcard_xrd).and_return(hcard_xml) - HCard.should_receive(:build).with(hcard_xml).and_return true - finger.hcard.should_not be_nil + allow(finger).to receive(:hcard_xrd).and_return(hcard_xml) + expect(HCard).to receive(:build).with(hcard_xml).and_return true + expect(finger.hcard).not_to be_nil end end describe '#webfinger_profile' do it 'constructs a new WebfingerProfile object' do - finger.stub(:webfinger_profile_xrd).and_return(webfinger_xrd) - WebfingerProfile.should_receive(:new).with(account, webfinger_xrd) + allow(finger).to receive(:webfinger_profile_xrd).and_return(webfinger_xrd) + expect(WebfingerProfile).to receive(:new).with(account, webfinger_xrd) finger.webfinger_profile end end describe '#webfinger_profile_url' do it 'returns the llrd link for a valid host meta' do - finger.stub(:host_meta_xrd).and_return(host_meta_xrd) - finger.webfinger_profile_url.should_not be_nil + allow(finger).to receive(:host_meta_xrd).and_return(host_meta_xrd) + expect(finger.webfinger_profile_url).not_to be_nil end it 'returns nil if no link is found' do - finger.stub(:host_meta_xrd).and_return(nil) - finger.webfinger_profile_url.should be_nil + allow(finger).to receive(:host_meta_xrd).and_return(nil) + expect(finger.webfinger_profile_url).to be_nil end end describe '#webfinger_profile_xrd' do it 'calls #get with the hcard_url' do - finger.stub(:hcard_url).and_return("url") - finger.should_receive(:get).with("url") + allow(finger).to receive(:hcard_url).and_return("url") + expect(finger).to receive(:get).with("url") finger.hcard_xrd end end describe '#make_person_from_webfinger' do it 'with an hcard and a webfinger_profile, it calls Person.create_from_webfinger' do - finger.stub(:hcard).and_return("hcard") - finger.stub(:webfinger_profile_xrd).and_return("webfinger_profile_xrd") - finger.stub(:webfinger_profile).and_return("webfinger_profile") - Person.should_receive(:create_from_webfinger).with("webfinger_profile", "hcard") + allow(finger).to receive(:hcard).and_return("hcard") + allow(finger).to receive(:webfinger_profile_xrd).and_return("webfinger_profile_xrd") + allow(finger).to receive(:webfinger_profile).and_return("webfinger_profile") + expect(Person).to receive(:create_from_webfinger).with("webfinger_profile", "hcard") finger.make_person_from_webfinger end it 'with an false xrd it does not call Person.create_from_webfinger' do - finger.stub(:webfinger_profile_xrd).and_return(false) - Person.should_not_receive(:create_from_webfinger) + allow(finger).to receive(:webfinger_profile_xrd).and_return(false) + expect(Person).not_to receive(:create_from_webfinger) finger.make_person_from_webfinger end end @@ -203,18 +203,18 @@ describe Webfinger do describe '#host_meta_url' do it 'should return canonical host-meta url for http' do finger.ssl = false - finger.host_meta_url.should == "http://bar.com/.well-known/host-meta" + expect(finger.host_meta_url).to eq("http://bar.com/.well-known/host-meta") end it 'can return the https version' do - finger.host_meta_url.should == "https://bar.com/.well-known/host-meta" + expect(finger.host_meta_url).to eq("https://bar.com/.well-known/host-meta") end end describe 'swizzle' do it 'gsubs out {uri} for the account' do string = "{uri} is the coolest" - finger.swizzle(string).should == "#{finger.account} is the coolest" + expect(finger.swizzle(string)).to eq("#{finger.account} is the coolest") end end end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 1f59a4bb2761aa1c74b868a1ea1946e1d5acc755..32788078090bd4420b502b94f44fac166abe19fa 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Notifier do +describe Notifier, :type => :mailer do let(:person) { FactoryGirl.create(:person) } before do @@ -10,11 +10,11 @@ describe Notifier do describe '.administrative' do it 'mails a user' do mails = Notifier.admin("Welcome to bureaucracy!", [bob]) - mails.length.should == 1 + expect(mails.length).to eq(1) mail = mails.first - mail.to.should == [bob.email] - mail.body.encoded.should match /Welcome to bureaucracy!/ - mail.body.encoded.should match /#{bob.username}/ + expect(mail.to).to eq([bob.email]) + expect(mail.body.encoded).to match /Welcome to bureaucracy!/ + expect(mail.body.encoded).to match /#{bob.username}/ end context 'mails a bunch of users' do @@ -26,19 +26,19 @@ describe Notifier do end it 'has a body' do mails = Notifier.admin("Welcome to bureaucracy!", @users) - mails.length.should == 5 + expect(mails.length).to eq(5) mails.each{|mail| this_user = @users.detect{|u| mail.to == [u.email]} - mail.body.encoded.should match /Welcome to bureaucracy!/ - mail.body.encoded.should match /#{this_user.username}/ + expect(mail.body.encoded).to match /Welcome to bureaucracy!/ + expect(mail.body.encoded).to match /#{this_user.username}/ } end it "has attachments" do mails = Notifier.admin("Welcome to bureaucracy!", @users, :attachments => [{:name => "retention stats", :file => "here is some file content"}]) - mails.length.should == 5 + expect(mails.length).to eq(5) mails.each{|mail| - mail.attachments.count.should == 1 + expect(mail.attachments.count).to eq(1) } end end @@ -47,19 +47,19 @@ describe Notifier do describe '.single_admin' do it 'mails a user' do mail = Notifier.single_admin("Welcome to bureaucracy!", bob) - mail.to.should == [bob.email] - mail.body.encoded.should match /Welcome to bureaucracy!/ - mail.body.encoded.should match /#{bob.username}/ + expect(mail.to).to eq([bob.email]) + expect(mail.body.encoded).to match /Welcome to bureaucracy!/ + expect(mail.body.encoded).to match /#{bob.username}/ end it 'has the layout' do mail = Notifier.single_admin("Welcome to bureaucracy!", bob) - mail.body.encoded.should match /change your notification settings/ + expect(mail.body.encoded).to match /change your notification settings/ end it 'has an optional attachment' do mail = Notifier.single_admin("Welcome to bureaucracy!", bob, :attachments => [{:name => "retention stats", :file => "here is some file content"}]) - mail.attachments.length.should == 1 + expect(mail.attachments.length).to eq(1) end end @@ -67,11 +67,11 @@ describe Notifier do let!(:request_mail) { Notifier.started_sharing(bob.id, person.id) } it 'goes to the right person' do - request_mail.to.should == [bob.email] + expect(request_mail.to).to eq([bob.email]) end it 'has the name of person sending the request' do - request_mail.body.encoded.include?(person.name).should be true + expect(request_mail.body.encoded.include?(person.name)).to be true end it 'has the css' do @@ -89,19 +89,19 @@ describe Notifier do end it 'TO: goes to the right person' do - @mail.to.should == [@user.email] + expect(@mail.to).to eq([@user.email]) end it 'SUBJECT: has the name of person mentioning in the subject' do - @mail.subject.should include(@sm.author.name) + expect(@mail.subject).to include(@sm.author.name) end it 'has the post text in the body' do - @mail.body.encoded.should include(@sm.text) + expect(@mail.body.encoded).to include(@sm.text) end it 'should not include translation fallback' do - @mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared') + expect(@mail.body.encoded).not_to include(I18n.translate 'notifier.a_post_you_shared') end end @@ -113,19 +113,19 @@ describe Notifier do end it 'TO: goes to the right person' do - @mail.to.should == [alice.email] + expect(@mail.to).to eq([alice.email]) end it 'BODY: contains the truncated original post' do - @mail.body.encoded.should include(@sm.message.plain_text) + expect(@mail.body.encoded).to include(@sm.message.plain_text) end it 'BODY: contains the name of person liking' do - @mail.body.encoded.should include(@like.author.name) + expect(@mail.body.encoded).to include(@like.author.name) end it 'should not include translation fallback' do - @mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared') + expect(@mail.body.encoded).not_to include(I18n.translate 'notifier.a_post_you_shared') end it 'can handle a reshare' do @@ -143,19 +143,19 @@ describe Notifier do end it 'TO: goes to the right person' do - @mail.to.should == [alice.email] + expect(@mail.to).to eq([alice.email]) end it 'BODY: contains the truncated original post' do - @mail.body.encoded.should include(@sm.message.plain_text) + expect(@mail.body.encoded).to include(@sm.message.plain_text) end it 'BODY: contains the name of person liking' do - @mail.body.encoded.should include(@reshare.author.name) + expect(@mail.body.encoded).to include(@reshare.author.name) end it 'should not include translation fallback' do - @mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared') + expect(@mail.body.encoded).not_to include(I18n.translate 'notifier.a_post_you_shared') end end @@ -178,30 +178,30 @@ describe Notifier do end it 'TO: goes to the right person' do - @mail.to.should == [bob.email] + expect(@mail.to).to eq([bob.email]) end it "FROM: contains the sender's name" do - @mail["From"].to_s.should == "\"#{@cnv.author.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>" + expect(@mail["From"].to_s).to eq("\"#{@cnv.author.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") end it 'SUBJECT: has a snippet of the post contents' do - @mail.subject.should == @cnv.subject + expect(@mail.subject).to eq(@cnv.subject) end it 'SUBJECT: has "Re:" if not the first message in a conversation' do @cnv.messages << Message.new(:text => 'yo', :author => eve.person) @mail = Notifier.private_message(bob.id, @cnv.author.id, @cnv.messages.last.id) - @mail.subject.should == "Re: #{@cnv.subject}" + expect(@mail.subject).to eq("Re: #{@cnv.subject}") end it 'BODY: contains the message text' do - @mail.body.encoded.should include(@cnv.messages.first.text) + expect(@mail.body.encoded).to include(@cnv.messages.first.text) end it 'should not include translation fallback' do - @mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared') + expect(@mail.body.encoded).not_to include(I18n.translate 'notifier.a_post_you_shared') end end @@ -213,28 +213,28 @@ describe Notifier do let(:comment_mail) {Notifier.comment_on_post(bob.id, person.id, comment.id).deliver} it 'TO: goes to the right person' do - comment_mail.to.should == [bob.email] + expect(comment_mail.to).to eq([bob.email]) end it "FROM: contains the sender's name" do - comment_mail["From"].to_s.should == "\"#{eve.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>" + expect(comment_mail["From"].to_s).to eq("\"#{eve.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") end it 'SUBJECT: has a snippet of the post contents, without markdown and without newlines' do - comment_mail.subject.should == "Re: Headline" + expect(comment_mail.subject).to eq("Re: Headline") end context 'BODY' do it "contains the comment" do - comment_mail.body.encoded.should include(comment.text) + expect(comment_mail.body.encoded).to include(comment.text) end it "contains the original post's link" do - comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true + expect(comment_mail.body.encoded.include?("#{comment.post.id.to_s}")).to be true end it 'should not include translation fallback' do - comment_mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared') + expect(comment_mail.body.encoded).not_to include(I18n.translate 'notifier.a_post_you_shared') end end @@ -242,9 +242,9 @@ describe Notifier do context post_type.to_s do let(:commented_post) { FactoryGirl.create(post_type, :author => bob.person) } it 'succeeds' do - proc { + expect { comment_mail - }.should_not raise_error + }.not_to raise_error end end end @@ -254,37 +254,37 @@ describe Notifier do let(:comment_mail) { Notifier.also_commented(bob.id, person.id, comment.id) } it 'TO: goes to the right person' do - comment_mail.to.should == [bob.email] + expect(comment_mail.to).to eq([bob.email]) end it 'FROM: has the name of person commenting as the sender' do - comment_mail["From"].to_s.should == "\"#{eve.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>" + expect(comment_mail["From"].to_s).to eq("\"#{eve.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") end it 'SUBJECT: has a snippet of the post contents, without markdown and without newlines' do - comment_mail.subject.should == "Re: Headline" + expect(comment_mail.subject).to eq("Re: Headline") end context 'BODY' do it "contains the comment" do - comment_mail.body.encoded.should include(comment.text) + expect(comment_mail.body.encoded).to include(comment.text) end it "contains the original post's link" do - comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true + expect(comment_mail.body.encoded.include?("#{comment.post.id.to_s}")).to be true end it 'should not include translation fallback' do - comment_mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared') + expect(comment_mail.body.encoded).not_to include(I18n.translate 'notifier.a_post_you_shared') end end [:reshare].each do |post_type| context post_type.to_s do let(:commented_post) { FactoryGirl.create(post_type, :author => bob.person) } it 'succeeds' do - proc { + expect { comment_mail - }.should_not raise_error + }.not_to raise_error end end end @@ -297,23 +297,23 @@ describe Notifier do end it 'goes to the right person' do - @confirm_email.to.should == [bob.unconfirmed_email] + expect(@confirm_email.to).to eq([bob.unconfirmed_email]) end it 'has the unconfirmed emil in the subject' do - @confirm_email.subject.should include(bob.unconfirmed_email) + expect(@confirm_email.subject).to include(bob.unconfirmed_email) end it 'has the unconfirmed emil in the body' do - @confirm_email.body.encoded.should include(bob.unconfirmed_email) + expect(@confirm_email.body.encoded).to include(bob.unconfirmed_email) end it 'has the receivers name in the body' do - @confirm_email.body.encoded.should include(bob.person.profile.first_name) + expect(@confirm_email.body.encoded).to include(bob.person.profile.first_name) end it 'has the activation link in the body' do - @confirm_email.body.encoded.should include(confirm_email_url(:token => bob.confirm_email_token)) + expect(@confirm_email.body.encoded).to include(confirm_email_url(:token => bob.confirm_email_token)) end end end @@ -321,9 +321,9 @@ describe Notifier do describe 'hashtags' do it 'escapes hashtags' do mails = Notifier.admin("#Welcome to bureaucracy!", [bob]) - mails.length.should == 1 + expect(mails.length).to eq(1) mail = mails.first - mail.body.encoded.should match "<p><a href=\"http://localhost:9887/tags/welcome\">#Welcome</a> to bureaucracy!</p>" + expect(mail.body.encoded).to match "<p><a href=\"http://localhost:9887/tags/welcome\">#Welcome</a> to bureaucracy!</p>" end end end diff --git a/spec/mailers/report_spec.rb b/spec/mailers/report_spec.rb index 9b41750a51d933e447b891d9fc484dabdb06cb28..10edd0dae79fdb36bebd3817b781908fd9405dba 100644 --- a/spec/mailers/report_spec.rb +++ b/spec/mailers/report_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Report do +describe Report, :type => :mailer do describe '#make_notification' do before do @remote = FactoryGirl.create(:person, :diaspora_handle => "remote@remote.net") diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 58eb639589c7916d3bcd0a06080c1ddadd19c5be..e714d839dabee6523990275eec5e7184e652c583 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -8,12 +8,12 @@ describe 'making sure the spec runner works' do it 'factory creates a user with a person saved' do user = FactoryGirl.create(:user) loaded_user = User.find(user.id) - loaded_user.person.owner_id.should == user.id + expect(loaded_user.person.owner_id).to eq(user.id) end describe 'fixtures' do it 'loads fixtures' do - User.count.should_not == 0 + expect(User.count).not_to eq(0) end end @@ -30,31 +30,31 @@ describe 'making sure the spec runner works' do it 'connects the first user to the second' do contact = @user1.contact_for @user2.person - contact.should_not be_nil - @user1.contacts.reload.include?(contact).should be true - @aspect1.contacts.include?(contact).should be true - contact.aspects.include?(@aspect1).should be true + expect(contact).not_to be_nil + expect(@user1.contacts.reload.include?(contact)).to be true + expect(@aspect1.contacts.include?(contact)).to be true + expect(contact.aspects.include?(@aspect1)).to be true end it 'connects the second user to the first' do contact = @user2.contact_for @user1.person - contact.should_not be_nil - @user2.contacts.reload.include?(contact).should be true - @aspect2.contacts.include?(contact).should be true - contact.aspects.include?(@aspect2).should be true + expect(contact).not_to be_nil + expect(@user2.contacts.reload.include?(contact)).to be true + expect(@aspect2.contacts.include?(contact)).to be true + expect(contact.aspects.include?(@aspect2)).to be true end it 'allows posting after running' do message = @user1.post(:status_message, :text => "Connection!", :to => @aspect1.id) - @user2.reload.visible_shareables(Post).should include message + expect(@user2.reload.visible_shareables(Post)).to include message end end describe '#post' do it 'creates a notification with a mention' do - lambda{ + expect{ alice.post(:status_message, :text => "@{Bob Grimn; #{bob.person.diaspora_handle}} you are silly", :to => alice.aspects.find_by_name('generic')) - }.should change(Notification, :count).by(1) + }.to change(Notification, :count).by(1) end end @@ -62,9 +62,9 @@ describe 'making sure the spec runner works' do it 'creates a conversation and a message' do conversation = create_conversation_with_message(alice, bob.person, "Subject", "Hey Bob") - conversation.participants.should == [alice.person, bob.person] - conversation.subject.should == "Subject" - conversation.messages.first.text.should == "Hey Bob" + expect(conversation.participants).to eq([alice.person, bob.person]) + expect(conversation.subject).to eq("Subject") + expect(conversation.messages.first.text).to eq("Hey Bob") end end end diff --git a/spec/models/account_deletion_spec.rb b/spec/models/account_deletion_spec.rb index e1c1cf4f8a7f1976ff3746e612e16d8a2d781046..00a165185248596a4c5a8a387ba6a4bb4324db9b 100644 --- a/spec/models/account_deletion_spec.rb +++ b/spec/models/account_deletion_spec.rb @@ -4,14 +4,14 @@ require 'spec_helper' -describe AccountDeletion do +describe AccountDeletion, :type => :model do it 'assigns the diaspora_handle from the person object' do a = AccountDeletion.new(:person => alice.person) - a.diaspora_handle.should == alice.person.diaspora_handle + expect(a.diaspora_handle).to eq(alice.person.diaspora_handle) end it 'fires a job after creation'do - Workers::DeleteAccount.should_receive(:perform_async).with(anything) + expect(Workers::DeleteAccount).to receive(:perform_async).with(anything) AccountDeletion.create(:person => alice.person) end @@ -22,18 +22,18 @@ describe AccountDeletion do end it 'creates a deleter' do - AccountDeleter.should_receive(:new).with(alice.person.diaspora_handle).and_return(double(:perform! => true)) + expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(:perform! => true)) @ad.perform! end it 'dispatches the account deletion if the user exists' do - @ad.should_receive(:dispatch) + expect(@ad).to receive(:dispatch) @ad.perform! end it 'does not dispatch an account deletion for non-local people' do deletion = AccountDeletion.new(:person => remote_raphael) - deletion.should_not_receive(:dispatch) + expect(deletion).not_to receive(:dispatch) deletion.perform! end @@ -51,7 +51,7 @@ describe AccountDeletion do end it 'creates a public postzord' do - Postzord::Dispatcher::Public.should_receive(:new).and_return(double.as_null_object) + expect(Postzord::Dispatcher::Public).to receive(:new).and_return(double.as_null_object) @ad = AccountDeletion.new(:person => alice.person) @ad.send(:dispatch) end @@ -62,7 +62,7 @@ describe AccountDeletion do @ad = AccountDeletion.new(:person => alice.person) alice.share_with(remote_raphael, alice.aspects.first) - @ad.subscribers(alice).should == [remote_raphael] + expect(@ad.subscribers(alice)).to eq([remote_raphael]) end it 'includes remote resharers' do @@ -71,7 +71,7 @@ describe AccountDeletion do r1 = FactoryGirl.create( :reshare, :author => remote_raphael, :root => sm) r2 = FactoryGirl.create( :reshare, :author => local_luke.person, :root => sm) - @ad.subscribers(alice).should == [remote_raphael] + expect(@ad.subscribers(alice)).to eq([remote_raphael]) end end @@ -82,11 +82,11 @@ describe AccountDeletion do end it 'should have a diaspora_handle' do - @xml.include?(alice.person.diaspora_handle).should == true + expect(@xml.include?(alice.person.diaspora_handle)).to eq(true) end it 'marshals the xml' do - AccountDeletion.from_xml(@xml).should be_valid + expect(AccountDeletion.from_xml(@xml)).to be_valid end end end diff --git a/spec/models/acts_as_taggable_on_tag_spec.rb b/spec/models/acts_as_taggable_on_tag_spec.rb index a54276661c9303d5e2c56d29d08c68c05ffb7bba..159c7c0350c83a8464e33c33449dc31fcfef5b6b 100644 --- a/spec/models/acts_as_taggable_on_tag_spec.rb +++ b/spec/models/acts_as_taggable_on_tag_spec.rb @@ -1,23 +1,23 @@ require 'spec_helper' -describe ActsAsTaggableOn::Tag do +describe ActsAsTaggableOn::Tag, :type => :model do describe '.autocomplete' do before do @tag = ActsAsTaggableOn::Tag.create(:name => "cats") end it 'downcases the tag name' do - ActsAsTaggableOn::Tag.autocomplete("CATS").should == [@tag] + expect(ActsAsTaggableOn::Tag.autocomplete("CATS")).to eq([@tag]) end it 'does an end where on tags' do - ActsAsTaggableOn::Tag.autocomplete("CAT").should == [@tag] + expect(ActsAsTaggableOn::Tag.autocomplete("CAT")).to eq([@tag]) end end describe ".normalize" do it "removes leading hash symbols" do - ActsAsTaggableOn::Tag.normalize("#mytag").should == "mytag" + expect(ActsAsTaggableOn::Tag.normalize("#mytag")).to eq("mytag") end it "removes punctuation and whitespace" do @@ -33,13 +33,13 @@ describe ActsAsTaggableOn::Tag do 'hash#inside' => 'hashinside', 'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters' }.each do |invalid, normalized| - ActsAsTaggableOn::Tag.normalize(invalid).should == normalized + expect(ActsAsTaggableOn::Tag.normalize(invalid)).to eq(normalized) end end it 'allows for love' do - ActsAsTaggableOn::Tag.normalize("<3").should == "<3" - ActsAsTaggableOn::Tag.normalize("#<3").should == "<3" + expect(ActsAsTaggableOn::Tag.normalize("<3")).to eq("<3") + expect(ActsAsTaggableOn::Tag.normalize("#<3")).to eq("<3") end end end diff --git a/spec/models/aspect_membership_spec.rb b/spec/models/aspect_membership_spec.rb index 7f4bc65f336fdaac112e9df6fd29f14cbdc656db..12b01fe240eb338571b44b686d7654d141fe1dcb 100644 --- a/spec/models/aspect_membership_spec.rb +++ b/spec/models/aspect_membership_spec.rb @@ -4,7 +4,7 @@ # require 'spec_helper' -describe AspectMembership do +describe AspectMembership, :type => :model do describe '#before_destroy' do before do @@ -12,17 +12,17 @@ describe AspectMembership do @contact = alice.contact_for(bob.person) @am = alice.aspects.where(:name => "generic").first.aspect_memberships.first - @am.stub(:user).and_return(alice) + allow(@am).to receive(:user).and_return(alice) end it 'calls disconnect if its the last aspect for the contact' do - alice.should_receive(:disconnect).with(@contact) + expect(alice).to receive(:disconnect).with(@contact) @am.destroy end it 'does not call disconnect if its not the last aspect for the contact' do - alice.should_not_receive(:disconnect) + expect(alice).not_to receive(:disconnect) alice.add_contact_to_aspect(@contact, @aspect) @am.destroy diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index a9aac12f8861a6f7898c5995e0427feb67a5affc..4315345ae1b44f07c3bcaf25dedffab33325704f 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -4,40 +4,40 @@ require 'spec_helper' -describe Aspect do +describe Aspect, :type => :model do describe 'creation' do before do @name = alice.aspects.first.name end it 'does not allow duplicate names' do - lambda { + expect { invalid_aspect = alice.aspects.create(:name => @name) - }.should_not change(Aspect, :count) + }.not_to change(Aspect, :count) end it 'validates case insensitiveness on names' do - lambda { + expect { invalid_aspect = alice.aspects.create(:name => @name.titleize) - }.should_not change(Aspect, :count) + }.not_to change(Aspect, :count) end it 'has a 20 character limit on names' do aspect = Aspect.new(:name => "this name is really too too too too too long") - aspect.valid?.should == false + expect(aspect.valid?).to eq(false) end it 'is able to have other users as contacts' do aspect = alice.aspects.create(:name => 'losers') Contact.create(:user => alice, :person => eve.person, :aspects => [aspect]) - aspect.contacts.where(:person_id => alice.person.id).should be_empty - aspect.contacts.where(:person_id => eve.person.id).should_not be_empty - aspect.contacts.size.should == 1 + expect(aspect.contacts.where(:person_id => alice.person.id)).to be_empty + expect(aspect.contacts.where(:person_id => eve.person.id)).not_to be_empty + expect(aspect.contacts.size).to eq(1) end it 'has a contacts_visible? method' do - alice.aspects.first.contacts_visible?.should be true + expect(alice.aspects.first.contacts_visible?).to be true end end @@ -45,7 +45,7 @@ describe Aspect do it 'has no uniqueness of name between users' do aspect = alice.aspects.create(:name => "New Aspect") aspect2 = eve.aspects.create(:name => aspect.name) - aspect2.should be_valid + expect(aspect2).to be_valid end end end diff --git a/spec/models/block_spec.rb b/spec/models/block_spec.rb index 5e3986aca728970dbc2b33a42e6587166435894b..e8b3683a63368513d1b93fe2b77f9128dc0be2d0 100644 --- a/spec/models/block_spec.rb +++ b/spec/models/block_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -describe Block do +describe Block, :type => :model do describe 'validations' do it 'doesnt allow you to block yourself' do block = alice.blocks.create(:person => alice.person) - block.errors[:person_id].size.should == 1 + expect(block.errors[:person_id].size).to eq(1) end end end \ No newline at end of file diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index fdb06639b15dd1c3b0e460c532d91bf1f9fbebd0..a377d142a9f40a2b523717f6a84cd8e579f0b5c9 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' require Rails.root.join("spec", "shared_behaviors", "relayable") -describe Comment do +describe Comment, :type => :model do before do @alices_aspect = alice.aspects.first @status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id) @@ -14,12 +14,12 @@ describe Comment do describe 'comment#notification_type' do it "returns 'comment_on_post' if the comment is on a post you own" do comment = alice.comment!(@status, "why so formal?") - comment.notification_type(bob, alice.person).should == Notifications::CommentOnPost + expect(comment.notification_type(bob, alice.person)).to eq(Notifications::CommentOnPost) end it 'returns false if the comment is not on a post you own and no one "also_commented"' do comment = alice.comment!(@status, "I simply felt like issuing a greeting. Do step off.") - comment.notification_type(eve, alice.person).should be false + expect(comment.notification_type(eve, alice.person)).to be false end context "also commented" do @@ -29,11 +29,11 @@ describe Comment do end it 'does not return also commented if the user commented' do - @comment.notification_type(eve, alice.person).should == false + expect(@comment.notification_type(eve, alice.person)).to eq(false) end it "returns 'also_commented' if another person commented on a post you commented on" do - @comment.notification_type(alice, alice.person).should == Notifications::AlsoCommented + expect(@comment.notification_type(alice, alice.person)).to eq(Notifications::AlsoCommented) end end end @@ -41,26 +41,26 @@ describe Comment do describe 'User#comment' do it "should be able to comment on one's own status" do alice.comment!(@status, "Yeah, it was great") - @status.reload.comments.first.text.should == "Yeah, it was great" + expect(@status.reload.comments.first.text).to eq("Yeah, it was great") end it "should be able to comment on a contact's status" do bob.comment!(@status, "sup dog") - @status.reload.comments.first.text.should == "sup dog" + expect(@status.reload.comments.first.text).to eq("sup dog") end it 'does not multi-post a comment' do - lambda { + expect { alice.comment!(@status, 'hello') - }.should change { Comment.count }.by(1) + }.to change { Comment.count }.by(1) end end describe 'counter cache' do it 'increments the counter cache on its post' do - lambda { + expect { alice.comment!(@status, "oh yeah") - }.should change{ + }.to change{ @status.reload.comments_count }.by(1) end @@ -77,11 +77,11 @@ describe Comment do end it 'serializes the sender handle' do - @xml.include?(@commenter.diaspora_handle).should be true + expect(@xml.include?(@commenter.diaspora_handle)).to be true end it 'serializes the post_guid' do - @xml.should include(@post.guid) + expect(@xml).to include(@post.guid) end describe 'marshalling' do @@ -90,11 +90,11 @@ describe Comment do end it 'marshals the author' do - @marshalled_comment.author.should == @commenter.person + expect(@marshalled_comment.author).to eq(@commenter.person) end it 'marshals the post' do - @marshalled_comment.post.should == @post + expect(@marshalled_comment.post).to eq(@post) end end end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index bb6dbd4480735d813f5d07df5dad25ca2421bfc8..9f837095217229d2602de15c116b9053af528d20 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper' -describe Contact do +describe Contact, :type => :model do describe 'aspect_memberships' do it 'deletes dependent aspect memberships' do - lambda{ + expect{ alice.contact_for(bob.person).destroy - }.should change(AspectMembership, :count).by(-1) + }.to change(AspectMembership, :count).by(-1) end end @@ -18,12 +18,12 @@ describe Contact do it 'requires a user' do contact.valid? - contact.errors.full_messages.should include "User can't be blank" + expect(contact.errors.full_messages).to include "User can't be blank" end it 'requires a person' do contact.valid? - contact.errors.full_messages.should include "Person can't be blank" + expect(contact.errors.full_messages).to include "Person can't be blank" end it 'ensures user is not making a contact for himself' do @@ -31,18 +31,18 @@ describe Contact do contact.user = alice contact.valid? - contact.errors.full_messages.should include "Cannot create self-contact" + expect(contact.errors.full_messages).to include "Cannot create self-contact" end it 'validates uniqueness' do person = FactoryGirl.create(:person) contact2 = alice.contacts.create(:person=>person) - contact2.should be_valid + expect(contact2).to be_valid contact.user = alice contact.person = person - contact.should_not be_valid + expect(contact).not_to be_valid end it "validates that the person's account is not closed" do @@ -50,18 +50,18 @@ describe Contact do contact = alice.contacts.new(:person=>person) - contact.should_not be_valid - contact.errors.full_messages.should include "Cannot be in contact with a closed account" + expect(contact).not_to be_valid + expect(contact.errors.full_messages).to include "Cannot be in contact with a closed account" end end context 'scope' do describe 'sharing' do it 'returns contacts with sharing true' do - lambda { + expect { alice.contacts.create!(:sharing => true, :person => FactoryGirl.create(:person)) alice.contacts.create!(:sharing => false, :person => FactoryGirl.create(:person)) - }.should change{ + }.to change{ Contact.sharing.count }.by(1) end @@ -69,10 +69,10 @@ describe Contact do describe 'receiving' do it 'returns contacts with sharing true' do - lambda { + expect { alice.contacts.create!(:receiving => true, :person => FactoryGirl.build(:person)) alice.contacts.create!(:receiving => false, :person => FactoryGirl.build(:person)) - }.should change{ + }.to change{ Contact.receiving.count }.by(1) end @@ -80,12 +80,12 @@ describe Contact do describe 'only_sharing' do it 'returns contacts with sharing true and receiving false' do - lambda { + expect { alice.contacts.create!(:receiving => true, :sharing => true, :person => FactoryGirl.build(:person)) alice.contacts.create!(:receiving => false, :sharing => true, :person => FactoryGirl.build(:person)) alice.contacts.create!(:receiving => false, :sharing => true, :person => FactoryGirl.build(:person)) alice.contacts.create!(:receiving => true, :sharing => false, :person => FactoryGirl.build(:person)) - }.should change{ + }.to change{ Contact.receiving.count }.by(2) end @@ -97,7 +97,7 @@ describe Contact do contact1 = FactoryGirl.create(:contact, :person => person) contact2 = FactoryGirl.create(:contact) contacts = Contact.all_contacts_of_person(person) - contacts.should == [contact1] + expect(contacts).to eq([contact1]) end end end @@ -137,19 +137,19 @@ describe Contact do end it "returns the target local user's contacts that are in the same aspect" do - @contact.contacts.map{|p| p.id}.should =~ [@eve.person].concat(@people1).map{|p| p.id} + expect(@contact.contacts.map{|p| p.id}).to match_array([@eve.person].concat(@people1).map{|p| p.id}) end it 'returns nothing if contacts_visible is false in that aspect' do @original_aspect.contacts_visible = false @original_aspect.save - @contact.contacts.should == [] + expect(@contact.contacts).to eq([]) end it 'returns no duplicate contacts' do [@alice, @eve].each {|c| @bob.add_contact_to_aspect(@bob.contact_for(c.person), @bob.aspects.last)} contact_ids = @contact.contacts.map{|p| p.id} - contact_ids.uniq.should == contact_ids + expect(contact_ids.uniq).to eq(contact_ids) end end @@ -158,7 +158,7 @@ describe Contact do @contact = @bob.contact_for @people1.first end it 'returns an empty array' do - @contact.contacts.should == [] + expect(@contact.contacts).to eq([]) end end end @@ -175,20 +175,20 @@ describe Contact do describe '#generate_request' do it 'makes a request' do - @contact.stub(:user).and_return(@user) + allow(@contact).to receive(:user).and_return(@user) request = @contact.generate_request - request.sender.should == @user.person - request.recipient.should == @person + expect(request.sender).to eq(@user.person) + expect(request.recipient).to eq(@person) end end describe '#dispatch_request' do it 'pushes to people' do - @contact.stub(:user).and_return(@user) + allow(@contact).to receive(:user).and_return(@user) m = double() - m.should_receive(:post) - Postzord::Dispatcher.should_receive(:build).and_return(m) + expect(m).to receive(:post) + expect(Postzord::Dispatcher).to receive(:build).and_return(m) @contact.dispatch_request end end @@ -200,7 +200,7 @@ describe Contact do end it "is called on validate" do - @contact.should_receive(:not_blocked_user) + expect(@contact).to receive(:not_blocked_user) @contact.valid? end @@ -209,11 +209,11 @@ describe Contact do block = alice.blocks.create(:person => person) bad_contact = alice.contacts.create(:person => person) - bad_contact.send(:not_blocked_user).should be false + expect(bad_contact.send(:not_blocked_user)).to be false end it "does not add to errors" do - @contact.send(:not_blocked_user).should be true + expect(@contact.send(:not_blocked_user)).to be true end end end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 69a54ea539cf96a474ffe069e17f83c850e647af..3a1c727aa60f05cc1840564764ad19ee2c7946e0 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Conversation do +describe Conversation, :type => :model do before do @user1 = alice @user2 = bob @@ -19,16 +19,16 @@ describe Conversation do end it 'creates a message on create' do - lambda{ + expect{ Conversation.create(@create_hash) - }.should change(Message, :count).by(1) + }.to change(Message, :count).by(1) end describe '#last_author' do it 'returns the last author to a conversation' do cnv = Conversation.create(@create_hash) Message.create(:author => @user2.person, :created_at => Time.now + 100, :text => "last", :conversation_id => cnv.id) - cnv.reload.last_author.id.should == @user2.person.id + expect(cnv.reload.last_author.id).to eq(@user2.person.id) end end @@ -45,7 +45,7 @@ describe Conversation do it 'returns nil if there are no unread messages in a conversation' do @cnv.conversation_visibilities.where(:person_id => @user1.person.id).first.tap { |cv| cv.unread = 0 }.save - @cnv.first_unread_message(@user1).should be_nil + expect(@cnv.first_unread_message(@user1)).to be_nil end end @@ -58,23 +58,23 @@ describe Conversation do describe 'serialization' do it 'serializes the message' do - @xml.gsub(/\s/, '').should include(@message.to_xml.to_s.gsub(/\s/, '')) + expect(@xml.gsub(/\s/, '')).to include(@message.to_xml.to_s.gsub(/\s/, '')) end it 'serializes the participants' do @create_hash[:participant_ids].each{|id| - @xml.should include(Person.find(id).diaspora_handle) + expect(@xml).to include(Person.find(id).diaspora_handle) } end it 'serializes the created_at time' do - @xml.should include(@message.created_at.to_s) + expect(@xml).to include(@message.created_at.to_s) end end describe '#subscribers' do it 'returns the recipients for the post owner' do - @cnv.subscribers(@user1).should == @user1.contacts.map{|c| c.person} + expect(@cnv.subscribers(@user1)).to eq(@user1.contacts.map{|c| c.person}) end end @@ -85,25 +85,25 @@ describe Conversation do end it 'creates a message' do - lambda{ + expect{ Diaspora::Parser.from_xml(@xml).receive(@user1, @user2.person) - }.should change(Message, :count).by(1) + }.to change(Message, :count).by(1) end it 'creates a conversation' do - lambda{ + expect{ Diaspora::Parser.from_xml(@xml).receive(@user1, @user2.person) - }.should change(Conversation, :count).by(1) + }.to change(Conversation, :count).by(1) end it 'creates appropriate visibilities' do - lambda{ + expect{ Diaspora::Parser.from_xml(@xml).receive(@user1, @user2.person) - }.should change(ConversationVisibility, :count).by(@participant_ids.size) + }.to change(ConversationVisibility, :count).by(@participant_ids.size) end it 'does not save before receive' do - Diaspora::Parser.from_xml(@xml).persisted?.should be false + expect(Diaspora::Parser.from_xml(@xml).persisted?).to be false end it 'notifies for the message' do - Notification.should_receive(:notify).once + expect(Notification).to receive(:notify).once Diaspora::Parser.from_xml(@xml).receive(@user1, @user2.person) end end diff --git a/spec/models/invitation_code_spec.rb b/spec/models/invitation_code_spec.rb index 9596952ddbedf35e7d5bf500077a4247d1aba2e3..9e3e95185b486539f0b48e56977b56c6d08d6ad6 100644 --- a/spec/models/invitation_code_spec.rb +++ b/spec/models/invitation_code_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -describe InvitationCode do +describe InvitationCode, :type => :model do it 'has a valid factory' do - FactoryGirl.build(:invitation_code).should be_valid + expect(FactoryGirl.build(:invitation_code)).to be_valid end it 'sets the count to a default value' do code = FactoryGirl.create(:invitation_code) - code.count.should > 0 + expect(code.count).to be > 0 end describe '#use!' do @@ -31,12 +31,12 @@ describe InvitationCode do end it 'grabs the set admin account for the pod...' do - InvitationCode.default_inviter_or(alice).username.should == 'bob' + expect(InvitationCode.default_inviter_or(alice).username).to eq('bob') end it '..or the given user' do AppConfig.admins.account = '' - InvitationCode.default_inviter_or(alice).username.should == 'alice' + expect(InvitationCode.default_inviter_or(alice).username).to eq('alice') end end end diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 8701bc50bbeee8209f15b0c304735331f3da8eb7..539b6158285cb26b58abb76b3eb88e53c0a30e01 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Invitation do +describe Invitation, :type => :model do let(:user) { alice } before do @@ -17,35 +17,35 @@ describe Invitation do end it 'is valid' do - @invitation.sender.should == user - @invitation.recipient.should == nil - @invitation.aspect.should == user.aspects.first - @invitation.language.should == "de" - @invitation.should be_valid + expect(@invitation.sender).to eq(user) + expect(@invitation.recipient).to eq(nil) + expect(@invitation.aspect).to eq(user.aspects.first) + expect(@invitation.language).to eq("de") + expect(@invitation).to be_valid end it 'ensures the sender is placing the recipient into one of his aspects' do @invitation.aspect = FactoryGirl.build(:aspect) - @invitation.should_not be_valid + expect(@invitation).not_to be_valid end end describe '#language' do it 'returns the correct language if the language is set' do @invitation = FactoryGirl.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first, :language => "de") - @invitation.language.should == "de" + expect(@invitation.language).to eq("de") end it 'returns en if no language is set' do @invitation = FactoryGirl.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first) - @invitation.language.should == "en" + expect(@invitation.language).to eq("en") end end it 'has a message' do @invitation = FactoryGirl.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first, :language => user.language) @invitation.message = "!" - @invitation.message.should == "!" + expect(@invitation.message).to eq("!") end @@ -57,8 +57,8 @@ describe Invitation do it 'returns an array of invites based on the emails passed in' do invites = Invitation.batch_invite(@emails, @opts) - invites.count.should be 2 - invites.all?{|x| x.persisted?}.should be true + expect(invites.count).to be 2 + expect(invites.all?{|x| x.persisted?}).to be true end it 'shares with people who are already on the pod' do @@ -67,7 +67,7 @@ describe Invitation do expect{ invites = Invitation.batch_invite(@emails, @opts) }.to change(eve.contacts, :count).by(1) - invites.count.should be 2 + expect(invites.count).to be 2 end end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb index 657a0a37e51fa19ba67df12448c6cb011200257b..11532bff69022d0874d3a3720d84968a99969fb1 100644 --- a/spec/models/like_spec.rb +++ b/spec/models/like_spec.rb @@ -5,13 +5,13 @@ require 'spec_helper' require Rails.root.join("spec", "shared_behaviors", "relayable") -describe Like do +describe Like, :type => :model do before do @status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id) end it 'has a valid factory' do - FactoryGirl.build(:like).should be_valid + expect(FactoryGirl.build(:like)).to be_valid end describe '#notification_type' do @@ -20,30 +20,30 @@ describe Like do end it 'should be notifications liked if you are the post owner' do - @like.notification_type(bob, alice.person).should be Notifications::Liked + expect(@like.notification_type(bob, alice.person)).to be Notifications::Liked end it 'should not notify you if you are the like-r' do - @like.notification_type(alice, alice.person).should be_nil + expect(@like.notification_type(alice, alice.person)).to be_nil end it 'should not notify you if you did not create the post' do - @like.notification_type(eve, alice.person).should be_nil + expect(@like.notification_type(eve, alice.person)).to be_nil end end describe 'counter cache' do it 'increments the counter cache on its post' do - lambda { + expect { alice.like!(@status) - }.should change{ @status.reload.likes_count }.by(1) + }.to change{ @status.reload.likes_count }.by(1) end it 'increments the counter cache on its comment' do comment = FactoryGirl.create(:comment, :post => @status) - lambda { + expect { alice.like!(comment) - }.should change{ comment.reload.likes_count }.by(1) + }.to change{ comment.reload.likes_count }.by(1) end end @@ -59,20 +59,20 @@ describe Like do @xml = @like.to_xml.to_s end it 'serializes the sender handle' do - @xml.include?(@liker.diaspora_handle).should be true + expect(@xml.include?(@liker.diaspora_handle)).to be true end it' serializes the post_guid' do - @xml.should include(@post.guid) + expect(@xml).to include(@post.guid) end describe 'marshalling' do before do @marshalled_like = Like.from_xml(@xml) end it 'marshals the author' do - @marshalled_like.author.should == @liker.person + expect(@marshalled_like.author).to eq(@liker.person) end it 'marshals the post' do - @marshalled_like.target.should == @post + expect(@marshalled_like.target).to eq(@post) end end end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index f3c45d654489de7f555dbd6bd320353a17673447..94eb12a08264389ed8d88946f68a5d0c2e5cd947 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe Location do +describe Location, :type => :model do describe 'before validation' do it 'should create new location when it has coordinates' do location = Location.new(coordinates:'1,2') - location.save.should be true + expect(location.save).to be true end it 'should not create new location when it does not have coordinates' do location = Location.new() - location.save.should be false + expect(location.save).to be false end end end diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb index bb4b9e507feff6c11a7933dc205f445270c04597..27444cbc5b3dd0ffd0ee4aa394c0acf18a11a169 100644 --- a/spec/models/mention_spec.rb +++ b/spec/models/mention_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Mention do +describe Mention, :type => :model do describe "#notify_recipient" do before do @user = alice @@ -14,12 +14,12 @@ describe Mention do it 'notifies the person being mentioned' do sm = @user.build_post(:status_message, :text => "hi @{#{bob.name}; #{bob.diaspora_handle}}", :to => @user.aspects.first) - Notification.should_receive(:notify).with(bob, anything(), sm.author) + expect(Notification).to receive(:notify).with(bob, anything(), sm.author) sm.receive(bob, alice.person) end it 'should not notify a user if they do not see the message' do - Notification.should_not_receive(:notify).with(alice, anything(), bob.person) + expect(Notification).not_to receive(:notify).with(alice, anything(), bob.person) sm2 = bob.build_post(:status_message, :text => "stuff @{#{alice.name}; #{alice.diaspora_handle}}", :to => bob.aspects.first) sm2.receive(eve, bob.person) end @@ -27,7 +27,7 @@ describe Mention do describe '#notification_type' do it "returns 'mentioned'" do - Mention.new.notification_type.should == Notifications::Mentioned + expect(Mention.new.notification_type).to eq(Notifications::Mentioned) end end @@ -40,9 +40,9 @@ describe Mention do @m = Mention.create!(:person => @mentioned_user.person, :post => @sm) @m.notify_recipient - lambda{ + expect{ @m.destroy - }.should change(Notification, :count).by(-1) + }.to change(Notification, :count).by(-1) end end end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index 08b718c69f536a8873501189e95bcb5db195a2ed..327348125cb4f4282410c6d30676e3eb64d0ec8c 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' require Rails.root.join("spec", "shared_behaviors", "relayable") -describe Message do +describe Message, :type => :model do before do @create_hash = { :author => bob.person, @@ -21,44 +21,44 @@ describe Message do it 'validates that the author is a participant in the conversation' do message = Message.new(:text => 'yo', :author => eve.person, :conversation_id => @conversation.id) - message.should_not be_valid + expect(message).not_to be_valid end describe '#notification_type' do it 'does not return anything for the author' do - @message.notification_type(bob, bob.person).should be_nil + expect(@message.notification_type(bob, bob.person)).to be_nil end it 'returns private mesage for an actual receiver' do - @message.notification_type(alice, bob.person).should == Notifications::PrivateMessage + expect(@message.notification_type(alice, bob.person)).to eq(Notifications::PrivateMessage) end end describe '#before_create' do it 'signs the message' do - @message.author_signature.should_not be_blank + expect(@message.author_signature).not_to be_blank end it 'signs the message author if author of conversation' do - @message.parent_author_signature.should_not be_blank + expect(@message.parent_author_signature).not_to be_blank end end describe 'serialization' do it 'serializes the text' do - @xml.should include(@message.text) + expect(@xml).to include(@message.text) end it 'serializes the author_handle' do - @xml.should include(@message.author.diaspora_handle) + expect(@xml).to include(@message.author.diaspora_handle) end it 'serializes the created_at time' do - @xml.should include(@message.created_at.to_s) + expect(@xml).to include(@message.created_at.to_s) end it 'serializes the conversation_guid time' do - @xml.should include(@message.conversation.guid) + expect(@xml).to include(@message.conversation.guid) end end @@ -98,12 +98,12 @@ describe Message do describe '#increase_unread' do it 'increments the conversation visiblity for the conversation' do - ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id, - :person_id => @local_luke.person.id).first.unread.should == 0 + expect(ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id, + :person_id => @local_luke.person.id).first.unread).to eq(0) @object_by_recipient.increase_unread(@local_luke) - ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id, - :person_id => @local_luke.person.id).first.unread.should == 1 + expect(ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id, + :person_id => @local_luke.person.id).first.unread).to eq(1) end end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index a0ec2c64120427e5d611c14adb065846840e5599..e3644db8cea4a24d82f7eaec95b29dbf9a3947f3 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Notification do +describe Notification, :type => :model do before do @sm = FactoryGirl.create(:status_message) @person = FactoryGirl.create(:person) @@ -21,7 +21,7 @@ describe Notification do it 'destoys the associated notification_actor' do @note.save - lambda{@note.destroy}.should change(NotificationActor, :count).by(-1) + expect{@note.destroy}.to change(NotificationActor, :count).by(-1) end describe '.for' do @@ -34,7 +34,7 @@ describe Notification do @opts.delete(:recipient_id) Notification.create(@opts.merge(:recipient_id => user2.id)) - Notification.for(@user).count.should == 4 + expect(Notification.for(@user).count).to eq(4) end end @@ -42,12 +42,12 @@ describe Notification do it "should set an unread notification to read" do @note.unread = true @note.set_read_state( true ) - @note.unread.should == false + expect(@note.unread).to eq(false) end it "should set an read notification to unread" do @note.unread = false @note.set_read_state( false ) - @note.unread.should == true + expect(@note.unread).to eq(true) end end @@ -57,9 +57,9 @@ describe Notification do it 'creates a new notificiation if the notification does not exist, or if it is unread' do @note.unread = false @note.save - Notification.count.should == 1 + expect(Notification.count).to eq(1) Notification.concatenate_or_create(@note.recipient, @note.target, @note.actors.first, Notifications::CommentOnPost) - Notification.count.should == 2 + expect(Notification.count).to eq(2) end end describe '.notify' do @@ -69,7 +69,7 @@ describe Notification do end it 'calls Notification.create if the object has a notification_type' do - Notification.should_receive(:make_notification).once + expect(Notification).to receive(:make_notification).once Notification.notify(@user, @request, @person) end @@ -80,9 +80,9 @@ describe Notification do :recipient_id => @user.id} n = Notifications::StartedSharing.new(opts) - n.stub(:recipient).and_return @user + allow(n).to receive(:recipient).and_return @user - @user.should_receive(:mail) + expect(@user).to receive(:mail) n.email_the_user(@request, @person) end end @@ -93,7 +93,7 @@ describe Notification do person2 = FactoryGirl.build(:person) notification = Notification.notify(@user, FactoryGirl.build(:like, :author => @person, :target => p), @person) notification2 = Notification.notify(@user, FactoryGirl.build(:like, :author => person2, :target => p), person2) - notification.id.should == notification2.id + expect(notification.id).to eq(notification2.id) end end @@ -103,7 +103,7 @@ describe Notification do person2 = FactoryGirl.build(:person) notification = Notification.notify(@user, FactoryGirl.build(:comment, :author => @person, :post => p), @person) notification2 = Notification.notify(@user, FactoryGirl.build(:comment, :author => person2, :post => p), person2) - notification.id.should == notification2.id + expect(notification.id).to eq(notification2.id) end end @@ -116,12 +116,12 @@ describe Notification do end it "updates the notification with a more people if one already exists" do - Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2 + expect(Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count).to eq(2) end it 'handles double comments from the same person without raising' do Postzord::Receiver::Private.new(@user3, :person => @user2.person, :object => @user2.comment!(@sm, "hey")).receive_object - Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2 + expect(Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count).to eq(2) end end end diff --git a/spec/models/notifications/private_message_spec.rb b/spec/models/notifications/private_message_spec.rb index f9ccffd14c7c44e7b74c21cfcfac9d0b4cb366bc..60c62b8aa05e9b22fcf5a33fd3fc19b3cc0cb592 100644 --- a/spec/models/notifications/private_message_spec.rb +++ b/spec/models/notifications/private_message_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Notifications::PrivateMessage do +describe Notifications::PrivateMessage, :type => :model do before do @user1 = alice @user2 = bob @@ -22,9 +22,9 @@ describe Notifications::PrivateMessage do describe '#make_notifiaction' do it 'does not save the notification' do - lambda{ + expect{ Notification.notify(@user2, @msg, @user1.person) - }.should_not change(Notification, :count) + }.not_to change(Notification, :count) end it 'does email the user' do @@ -33,11 +33,11 @@ describe Notifications::PrivateMessage do :recipient_id => @user2.id} n = Notifications::PrivateMessage.new(opts) - Notifications::PrivateMessage.stub(:make_notification).and_return(n) + allow(Notifications::PrivateMessage).to receive(:make_notification).and_return(n) Notification.notify(@user2, @msg, @user1.person) - n.stub(:recipient).and_return @user2 + allow(n).to receive(:recipient).and_return @user2 - @user2.should_receive(:mail) + expect(@user2).to receive(:mail) n.email_the_user(@msg, @user1.person) end @@ -49,8 +49,8 @@ describe Notifications::PrivateMessage do message.save n = Notifications::PrivateMessage.make_notification(@user2, message, @user1.person, Notifications::PrivateMessage) - ConversationVisibility.where(:conversation_id => message.reload.conversation.id, - :person_id => @user2.person.id).first.unread.should == 1 + expect(ConversationVisibility.where(:conversation_id => message.reload.conversation.id, + :person_id => @user2.person.id).first.unread).to eq(1) end it 'increases user unread count - author user 2' do @@ -61,8 +61,8 @@ describe Notifications::PrivateMessage do message.save n = Notifications::PrivateMessage.make_notification(@user1, message, @user2.person, Notifications::PrivateMessage) - ConversationVisibility.where(:conversation_id => message.reload.conversation.id, - :person_id => @user1.person.id).first.unread.should == 1 + expect(ConversationVisibility.where(:conversation_id => message.reload.conversation.id, + :person_id => @user1.person.id).first.unread).to eq(1) end end diff --git a/spec/models/notifications/reshared_spec.rb b/spec/models/notifications/reshared_spec.rb index fdd709f8299a5fca5103bd49ec3be131c66ce10f..58836069c6284d3528b87473a6131e277b7df40d 100644 --- a/spec/models/notifications/reshared_spec.rb +++ b/spec/models/notifications/reshared_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Notifications::Reshared do +describe Notifications::Reshared, :type => :model do before do @sm = FactoryGirl.build(:status_message, :author => alice.person, :public => true) @reshare1 = FactoryGirl.build(:reshare, :root => @sm) @@ -13,7 +13,7 @@ describe Notifications::Reshared do describe 'Notification.notify' do it 'calls concatenate_or_create with root post' do - Notifications::Reshared.should_receive(:concatenate_or_create).with(alice, @reshare1.root, @reshare1.author, Notifications::Reshared) + expect(Notifications::Reshared).to receive(:concatenate_or_create).with(alice, @reshare1.root, @reshare1.author, Notifications::Reshared) Notification.notify(alice, @reshare1, @reshare1.author) end @@ -21,23 +21,23 @@ describe Notifications::Reshared do describe '#mail_job' do it "does not raise" do - lambda{ + expect{ Notifications::Reshared.new.mail_job - }.should_not raise_error + }.not_to raise_error end end describe '#concatenate_or_create' do it 'creates a new notification if one does not already exist' do - Notifications::Reshared.should_receive(:make_notification).with(alice, @reshare1.root, @reshare1.author, Notifications::Reshared) + expect(Notifications::Reshared).to receive(:make_notification).with(alice, @reshare1.root, @reshare1.author, Notifications::Reshared) Notifications::Reshared.concatenate_or_create(alice, @reshare1.root, @reshare1.author, Notifications::Reshared) end it "appends the actors to the aldeady existing notification" do note = Notifications::Reshared.make_notification(alice, @reshare1.root, @reshare1.author, Notifications::Reshared) - lambda{ + expect{ Notifications::Reshared.concatenate_or_create(alice, @reshare2.root, @reshare2.author, Notifications::Reshared) - }.should change(note.actors, :count).by(1) + }.to change(note.actors, :count).by(1) end end end diff --git a/spec/models/participation_spec.rb b/spec/models/participation_spec.rb index af93bc105aca87aa215ab719da8da28563c4319b..658c0cc8ef8447e420d3e1e092617c2b79c6fe40 100644 --- a/spec/models/participation_spec.rb +++ b/spec/models/participation_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Participation do +describe Participation, :type => :model do describe 'it is relayable' do before do @status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id) diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 809435b3bbbdf7742430d26b62800956f654c45f..f6bc6f123918bd355d89abaf54c0fcf7b852957b 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Person do +describe Person, :type => :model do before do @user = bob @@ -12,20 +12,20 @@ describe Person do end it 'always has a profile' do - Person.new.profile.should_not be_nil + expect(Person.new.profile).not_to be_nil end it 'does not save automatically' do - Person.new.persisted?.should be false - Person.new.profile.persisted?.should be false + expect(Person.new.persisted?).to be false + expect(Person.new.profile.persisted?).to be false end context 'scopes' do describe '.for_json' do it 'does not select public keys' do - proc { + expect { Person.for_json.first.serialized_public_key - }.should raise_error ActiveModel::MissingAttributeError + }.to raise_error ActiveModel::MissingAttributeError end it 'selects distinct people' do @@ -35,7 +35,7 @@ describe Person do where(:contacts => {:user_id => bob.id}, :aspect_memberships => {:aspect_id => bob.aspect_ids}).map{|p| p.id} - person_ids.uniq.should == person_ids + expect(person_ids.uniq).to eq(person_ids) end end @@ -53,11 +53,11 @@ describe Person do describe '.find_person_from_guid_or_username' do it 'searchs for a person if id is passed' do - Person.find_from_guid_or_username(:id => @person.guid).id.should == @person.id + expect(Person.find_from_guid_or_username(:id => @person.guid).id).to eq(@person.id) end it 'searchs a person from a user if username is passed' do - Person.find_from_guid_or_username(:username => @user.username).id.should == @user.person.id + expect(Person.find_from_guid_or_username(:username => @user.username).id).to eq(@user.person.id) end it 'throws active record not found exceptions if no person is found via id' do @@ -76,17 +76,17 @@ describe Person do describe '.all_from_aspects' do it "pulls back the right people given all a user's aspects" do aspect_ids = bob.aspects.map(&:id) - Person.all_from_aspects(aspect_ids, bob).map(&:id).should =~ bob.contacts.includes(:person).map{|c| c.person.id} + expect(Person.all_from_aspects(aspect_ids, bob).map(&:id)).to match_array(bob.contacts.includes(:person).map{|c| c.person.id}) end it "pulls back the right people given a subset of aspects" do aspect_ids = bob.aspects.first.id - Person.all_from_aspects(aspect_ids, bob).map(&:id).should =~ bob.aspects.first.contacts.includes(:person).map{|c| c.person.id} + expect(Person.all_from_aspects(aspect_ids, bob).map(&:id)).to match_array(bob.aspects.first.contacts.includes(:person).map{|c| c.person.id}) end it "respects aspects given a user" do aspect_ids = alice.aspects.map(&:id) - Person.all_from_aspects(aspect_ids, bob).map(&:id).should == [] + expect(Person.all_from_aspects(aspect_ids, bob).map(&:id)).to eq([]) end end @@ -94,33 +94,33 @@ describe Person do it 'pulls back users who reshared the status message of a user' do sm = FactoryGirl.create(:status_message, :author => alice.person, :public => true) reshare = FactoryGirl.create(:reshare, :root => sm) - Person.who_have_reshared_a_users_posts(alice).should == [reshare.author] + expect(Person.who_have_reshared_a_users_posts(alice)).to eq([reshare.author]) end end end describe "delegating" do it "delegates last_name to the profile" do - @person.last_name.should == @person.profile.last_name + expect(@person.last_name).to eq(@person.profile.last_name) @person.profile.update_attributes(:last_name => "Heathers") - @person.reload.last_name.should == "Heathers" + expect(@person.reload.last_name).to eq("Heathers") end end describe "valid url" do it 'should allow for https urls' do person = FactoryGirl.build(:person, :url => "https://example.com") - person.should be_valid + expect(person).to be_valid end it 'should always return the correct receive url' do person = FactoryGirl.build(:person, :url => "https://example.com/a/bit/messed/up") - person.receive_url.should == "https://example.com/receive/users/#{person.guid}/" + expect(person.receive_url).to eq("https://example.com/receive/users/#{person.guid}/") end it 'should allow ports in the url' do person = FactoryGirl.build(:person, :url => "https://example.com:3000/") - person.url.should == "https://example.com:3000/" + expect(person.url).to eq("https://example.com:3000/") end end @@ -128,31 +128,31 @@ describe Person do context 'local people' do it 'uses the pod config url to set the diaspora_handle' do new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person - new_person.diaspora_handle.should == "foo123#{User.diaspora_id_host}" + expect(new_person.diaspora_handle).to eq("foo123#{User.diaspora_id_host}") end it 'does not include www if it is set in app config' do - AppConfig.stub(:pod_uri).and_return(Addressable::URI.parse('https://www.foobar.com/')) + allow(AppConfig).to receive(:pod_uri).and_return(Addressable::URI.parse('https://www.foobar.com/')) new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person - new_person.diaspora_handle.should == "foo123@foobar.com" + expect(new_person.diaspora_handle).to eq("foo123@foobar.com") end end context 'remote people' do it 'stores the diaspora_handle in the database' do - @person.diaspora_handle.include?(AppConfig.pod_uri.host).should be false + expect(@person.diaspora_handle.include?(AppConfig.pod_uri.host)).to be false end end describe 'validation' do it 'is unique' do person_two = FactoryGirl.build(:person, :diaspora_handle => @person.diaspora_handle) - person_two.should_not be_valid + expect(person_two).not_to be_valid end it 'is case insensitive' do person_two = FactoryGirl.build(:person, :diaspora_handle => @person.diaspora_handle.upcase) - person_two.should_not be_valid + expect(person_two).not_to be_valid end end end @@ -165,25 +165,25 @@ describe Person do context 'with only first name' do it 'should return their first name for name' do - Person.name_from_attrs(@profile.first_name, nil, @profile.diaspora_handle).should == @profile.first_name.strip + expect(Person.name_from_attrs(@profile.first_name, nil, @profile.diaspora_handle)).to eq(@profile.first_name.strip) end end context 'with only last name' do it 'should return their last name for name' do - Person.name_from_attrs(nil, @profile.last_name, @profile.diaspora_handle).should == @profile.last_name.strip + expect(Person.name_from_attrs(nil, @profile.last_name, @profile.diaspora_handle)).to eq(@profile.last_name.strip) end end context 'with both first and last name' do it 'should return their composed name for name' do - Person.name_from_attrs(@profile.first_name, @profile.last_name, @profile.diaspora_handle).should == "#{@profile.first_name.strip} #{@profile.last_name.strip}" + expect(Person.name_from_attrs(@profile.first_name, @profile.last_name, @profile.diaspora_handle)).to eq("#{@profile.first_name.strip} #{@profile.last_name.strip}") end end context 'without first nor last name' do it 'should display their diaspora handle' do - Person.name_from_attrs(nil, nil, @profile.diaspora_handle).should == @profile.diaspora_handle + expect(Person.name_from_attrs(nil, nil, @profile.diaspora_handle)).to eq(@profile.diaspora_handle) end end end @@ -191,7 +191,7 @@ describe Person do describe '#name' do it 'calls Person.name_from_attrs' do profile = alice.person.profile - Person.should_receive(:name_from_attrs).with(profile.first_name, profile.last_name, profile.person.diaspora_handle) + expect(Person).to receive(:name_from_attrs).with(profile.first_name, profile.last_name, profile.person.diaspora_handle) alice.name end @@ -199,7 +199,7 @@ describe Person do profile = alice.person.profile profile.first_name = "maxwell " profile.last_name = "salzberg " - alice.name.should == "maxwell salzberg" + expect(alice.name).to eq("maxwell salzberg") end end @@ -209,11 +209,11 @@ describe Person do end it 'should serialize to xml' do - @xml.include?("person").should == true + expect(@xml.include?("person")).to eq(true) end it 'should have a profile in its xml' do - @xml.include?("first_name").should == true + expect(@xml.include?("first_name")).to eq(true) end end @@ -222,8 +222,8 @@ describe Person do person_message = FactoryGirl.create(:status_message, :author => @person) person_two = FactoryGirl.create(:person) - @person.owns?(person_message).should be true - person_two.owns?(person_message).should be false + expect(@person.owns?(person_message)).to be true + expect(person_two.owns?(person_message)).to be false end describe "disconnecting" do @@ -235,31 +235,31 @@ describe Person do it 'should not delete an orphaned contact' do @user.contacts.create(:person => @person, :aspects => [@aspect]) - lambda { @user.disconnect(@user.contact_for(@person)) }.should_not change(Person, :count) + expect { @user.disconnect(@user.contact_for(@person)) }.not_to change(Person, :count) end it 'should not delete an un-orphaned contact' do @user.contacts.create(:person => @person, :aspects => [@aspect]) @user2.contacts.create(:person => @person, :aspects => [@aspect2]) - lambda { @user.disconnect(@user.contact_for(@person)) }.should_not change(Person, :count) + expect { @user.disconnect(@user.contact_for(@person)) }.not_to change(Person, :count) end end describe "#first_name" do it 'returns username if first_name is not present in profile' do alice.person.profile.update_attributes(:first_name => "") - alice.person.first_name.should == alice.username + expect(alice.person.first_name).to eq(alice.username) end it 'returns first words in first_name if first_name is present' do alice.person.profile.update_attributes(:first_name => "First Mid Last") - alice.person.first_name.should == "First Mid" + expect(alice.person.first_name).to eq("First Mid") end it 'returns first word in first_name if first_name is present' do alice.person.profile.update_attributes(:first_name => "Alice") - alice.person.first_name.should == "Alice" + expect(alice.person.first_name).to eq("Alice") end end @@ -311,49 +311,49 @@ describe Person do @casey_grippi.profile.save! people = Person.search("AAA", @user) - people.map { |p| p.name }.should == [@yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map { |p| p.name } + expect(people.map { |p| p.name }).to eq([@yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map { |p| p.name }) end it 'returns nothing on an empty query' do people = Person.search("", @user) - people.should be_empty + expect(people).to be_empty end it 'returns nothing on a one-character query' do people = Person.search("i", @user) - people.should be_empty + expect(people).to be_empty end it 'returns results for partial names' do people = Person.search("Eug", @user) - people.count.should == 1 - people.first.should == @eugene_weinstein + expect(people.count).to eq(1) + expect(people.first).to eq(@eugene_weinstein) people = Person.search("wEi", @user) - people.count.should == 1 - people.first.should == @eugene_weinstein + expect(people.count).to eq(1) + expect(people.first).to eq(@eugene_weinstein) people = Person.search("gri", @user) - people.count.should == 2 - people.first.should == @robert_grimm - people.second.should == @casey_grippi + expect(people.count).to eq(2) + expect(people.first).to eq(@robert_grimm) + expect(people.second).to eq(@casey_grippi) end it 'returns results for full names' do people = Person.search("Casey Grippi", @user) - people.count.should == 1 - people.first.should == @casey_grippi + expect(people.count).to eq(1) + expect(people.first).to eq(@casey_grippi) end it 'only displays searchable people' do invisible_person = FactoryGirl.build(:person, :profile => FactoryGirl.build(:profile, :searchable => false, :first_name => "johnson")) - Person.search("johnson", @user).should_not include invisible_person - Person.search("", @user).should_not include invisible_person + expect(Person.search("johnson", @user)).not_to include invisible_person + expect(Person.search("", @user)).not_to include invisible_person end it 'returns results for Diaspora handles' do people = Person.search(@robert_grimm.diaspora_handle, @user) - people.should == [@robert_grimm] + expect(people).to eq([@robert_grimm]) end it "puts the searching user's contacts first" do @@ -372,7 +372,7 @@ describe Person do @user.contacts.create(:person => @casey_grippi, :aspects => [@user.aspects.first]) people = Person.search("AAA", @user) - people.map { |p| p.name }.should == [@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map { |p| p.name } + expect(people.map { |p| p.name }).to eq([@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map { |p| p.name }) end end @@ -383,29 +383,29 @@ describe Person do describe '.by_account_identifier' do it 'should find a local users person' do p = Person.by_account_identifier(user.diaspora_handle) - p.should == user.person + expect(p).to eq(user.person) end it 'should find remote users person' do p = Person.by_account_identifier(person.diaspora_handle) - p.should == person + expect(p).to eq(person) end it 'should downcase and strip the diaspora_handle' do dh_upper = " " + user.diaspora_handle.upcase + " " - Person.by_account_identifier(dh_upper).should == user.person + expect(Person.by_account_identifier(dh_upper)).to eq(user.person) end it "finds a local person with a mixed-case username" do user = FactoryGirl.create(:user, :username => "SaMaNtHa") person = Person.by_account_identifier(user.person.diaspora_handle) - person.should == user.person + expect(person).to eq(user.person) end it "is case insensitive" do user1 = FactoryGirl.create(:user, :username => "SaMaNtHa") person = Person.by_account_identifier(user1.person.diaspora_handle.upcase) - person.should == user1.person + expect(person).to eq(user1.person) end it 'should only find people who are exact matches (1/2)' do @@ -413,14 +413,14 @@ describe Person do person = FactoryGirl.create(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") user.person.diaspora_handle = "tom@tom.joindiaspora.com" user.person.save - Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com" + expect(Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle).to eq("tom@tom.joindiaspora.com") end it 'should only find people who are exact matches (2/2)' do person = FactoryGirl.create(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") person1 = FactoryGirl.create(:person, :diaspora_handle => "tom@tom.joindiaspora.comm") f = Person.by_account_identifier("tom@tom.joindiaspora.com") - f.should be nil + expect(f).to be nil end @@ -429,46 +429,46 @@ describe Person do describe '.local_by_account_identifier' do it 'should find local users people' do p = Person.local_by_account_identifier(user.diaspora_handle) - p.should == user.person + expect(p).to eq(user.person) end it 'should not find a remote person' do p = Person.local_by_account_identifier(@person.diaspora_handle) - p.should be nil + expect(p).to be nil end it 'should call .by_account_identifier' do - Person.should_receive(:by_account_identifier) + expect(Person).to receive(:by_account_identifier) Person.local_by_account_identifier(@person.diaspora_handle) end end end describe '#has_photos?' do it 'returns false if the user has no photos' do - alice.person.has_photos?.should be false + expect(alice.person.has_photos?).to be false end it 'returns true if the user has photos' do alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id) - alice.person.has_photos?.should be true + expect(alice.person.has_photos?).to be true end end describe '#as_json' do it 'returns a hash representation of a person' do - @person.as_json.should == { + expect(@person.as_json).to eq({ :id => @person.id, :guid => @person.guid, :name => @person.name, :avatar => @person.profile.image_url(:thumb_medium), :handle => @person.diaspora_handle, :url => Rails.application.routes.url_helpers.person_path(@person), - } + }) end it 'return tags if asked' do - @person.as_json(:includes => "tags"). - should == @person.as_json.merge(:tags => @person.profile.tags.map { |t| "##{t.name}" }) + expect(@person.as_json(:includes => "tags")). + to eq(@person.as_json.merge(:tags => @person.profile.tags.map { |t| "##{t.name}" })) end end @@ -476,11 +476,11 @@ describe Person do describe "when the pod owner hasn't set up any community spotlight members" do it 'returns people with the community spotlight role' do Role.add_spotlight(bob.person) - Person.community_spotlight.should be_present + expect(Person.community_spotlight).to be_present end it "returns an empty array" do - Person.community_spotlight.should == [] + expect(Person.community_spotlight).to eq([]) end end end @@ -494,7 +494,7 @@ describe Person do it "calls #update_person_url given an array of users and a url" do people = [double.as_null_object, double.as_null_object, double.as_null_object] people.each do |person| - person.should_receive(:update_url).with(@url) + expect(person).to receive(:update_url).with(@url) end Person.url_batch_update(people, @url) end @@ -514,7 +514,7 @@ describe Person do describe '#lock_access!' do it 'sets the closed_account flag' do @person.lock_access! - @person.reload.closed_account.should be true + expect(@person.reload.closed_account).to be true end end @@ -524,7 +524,7 @@ describe Person do end it 'calls Profile#tombstone!' do - @person.profile.should_receive(:tombstone!) + expect(@person.profile).to receive(:tombstone!) @person.clear_profile! end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index d6c1fd13db09a1759285d52664c01b81a1a8034e..5b568f40130de18c1b80adf66bff508055c4c696 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -11,7 +11,7 @@ def with_carrierwave_processing(&block) val end -describe Photo do +describe Photo, :type => :model do before do @user = alice @aspect = @user.aspects.first @@ -28,18 +28,18 @@ describe Photo do describe 'after_create' do it 'calls #queue_processing_job' do - @photo.should_receive(:queue_processing_job) + expect(@photo).to receive(:queue_processing_job) @photo.save! end end it 'is mutable' do - @photo.mutable?.should == true + expect(@photo.mutable?).to eq(true) end it 'has a random string key' do - @photo2.random_string.should_not be nil + expect(@photo2.random_string).not_to be nil end describe '#diaspora_initialize' do @@ -50,13 +50,13 @@ describe Photo do end it 'sets the persons diaspora handle' do - @photo.diaspora_handle.should == @user.person.diaspora_handle + expect(@photo.diaspora_handle).to eq(@user.person.diaspora_handle) end it 'sets the random prefix' do photo_double = double.as_null_object - photo_double.should_receive(:random_string=) - Photo.stub(:new).and_return(photo_double) + expect(photo_double).to receive(:random_string=) + allow(Photo).to receive(:new).and_return(photo_double) Photo.diaspora_initialize( :author => @user.person, :user_file => @image) @@ -64,8 +64,8 @@ describe Photo do context "with user file" do it 'builds the photo without saving' do - @photo.created_at.nil?.should be true - @photo.unprocessed_image.read.nil?.should be false + expect(@photo.created_at.nil?).to be true + expect(@photo.unprocessed_image.read.nil?).to be false end end @@ -74,8 +74,8 @@ describe Photo do url = "https://service.com/user/profile_image" photo_double = double.as_null_object - photo_double.should_receive(:remote_unprocessed_image_url=).with(url) - Photo.stub(:new).and_return(photo_double) + expect(photo_double).to receive(:remote_unprocessed_image_url=).with(url) + allow(Photo).to receive(:new).and_return(photo_double) Photo.diaspora_initialize( :author => @user.person, :image_url => url) @@ -94,19 +94,19 @@ describe Photo do it 'sets a remote url' do @photo.update_remote_path - @photo.remote_photo_path.should include("http") - @photo.remote_photo_name.should include(".png") + expect(@photo.remote_photo_path).to include("http") + expect(@photo.remote_photo_name).to include(".png") end end it 'should save a photo' do @photo.unprocessed_image.store! File.open(@fixture_name) - @photo.save.should == true + expect(@photo.save).to eq(true) binary = @photo.unprocessed_image.read.force_encoding('BINARY') fixture_binary = File.read(@fixture_name).force_encoding('BINARY') - binary.should == fixture_binary + expect(binary).to eq(fixture_binary) end context 'with a saved photo' do @@ -117,7 +117,7 @@ describe Photo do end it 'should have text' do @photo.text= "cool story, bro" - @photo.save.should be true + expect(@photo.save).to be true end it 'should remove its reference in user profile if it is referred' do @@ -126,26 +126,26 @@ describe Photo do @user.profile.image_url = @photo.url(:thumb_large) @user.person.save @photo.destroy - Person.find(@user.person.id).profile[:image_url].should be_nil + expect(Person.find(@user.person.id).profile[:image_url]).to be_nil end it 'should not use the imported filename as the url' do - @photo.url.should_not include @fixture_filename - @photo.url(:thumb_medium).should_not include ("/" + @fixture_filename) + expect(@photo.url).not_to include @fixture_filename + expect(@photo.url(:thumb_medium)).not_to include ("/" + @fixture_filename) end it 'should save the image dimensions' do - @photo.width.should == 40 - @photo.height.should == 40 + expect(@photo.width).to eq(40) + expect(@photo.height).to eq(40) end end describe 'non-image files' do it 'should not store' do file = File.open(@fail_fixture_name) - lambda { + expect { @photo.unprocessed_image.store! file - }.should raise_error CarrierWave::IntegrityError, 'You are not allowed to upload "xml" files, allowed types: jpg, jpeg, png, gif' + }.to raise_error CarrierWave::IntegrityError, 'You are not allowed to upload "xml" files, allowed types: jpg, jpeg, png, gif' end end @@ -159,18 +159,18 @@ describe Photo do end it 'serializes the url' do - @xml.include?(@saved_photo.remote_photo_path).should be true - @xml.include?(@saved_photo.remote_photo_name).should be true + expect(@xml.include?(@saved_photo.remote_photo_path)).to be true + expect(@xml.include?(@saved_photo.remote_photo_name)).to be true end it 'serializes the diaspora_handle' do - @xml.include?(@user.diaspora_handle).should be true + expect(@xml.include?(@user.diaspora_handle)).to be true end it 'serializes the height and width' do - @xml.should include 'height' - @xml.include?('width').should be true - @xml.include?('40').should be true + expect(@xml).to include 'height' + expect(@xml.include?('width')).to be true + expect(@xml.include?('40')).to be true end end @@ -195,21 +195,21 @@ describe Photo do zord.parse_and_receive(xml) new_photo = Photo.where(:guid => @saved_photo.guid).first - new_photo.url.nil?.should be false - new_photo.url.include?(url).should be true - new_photo.url(:thumb_medium).include?(thumb_url).should be true + expect(new_photo.url.nil?).to be false + expect(new_photo.url.include?(url)).to be true + expect(new_photo.url(:thumb_medium).include?(thumb_url)).to be true end end context "commenting" do it "accepts comments if there is no parent status message" do - proc{ @user.comment!(@photo, "big willy style") }.should change(@photo.comments, :count).by(1) + expect{ @user.comment!(@photo, "big willy style") }.to change(@photo.comments, :count).by(1) end end describe '#queue_processing_job' do it 'should queue a job to process the images' do - Workers::ProcessPhoto.should_receive(:perform_async).with(@photo.id) + expect(Workers::ProcessPhoto).to receive(:perform_async).with(@photo.id) @photo.queue_processing_job end end diff --git a/spec/models/pod_spec.rb b/spec/models/pod_spec.rb index 2e1b8e0b30a15007b76fae3074d0171a95b41812..7aee2dfa2efa8e3e81926f4f7bbae6dc7dd73bde 100644 --- a/spec/models/pod_spec.rb +++ b/spec/models/pod_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe Pod do +describe Pod, :type => :model do describe '.find_or_create_by' do it 'takes a url, and makes one by host' do pod = Pod.find_or_create_by(url: 'https://joindiaspora.com/maxwell') - pod.host.should == 'joindiaspora.com' + expect(pod.host).to eq('joindiaspora.com') end it 'sets ssl boolean(side-effect)' do pod = Pod.find_or_create_by(url: 'https://joindiaspora.com/maxwell') - pod.ssl.should be true + expect(pod.ssl).to be true end end end diff --git a/spec/models/poll_answer_spec.rb b/spec/models/poll_answer_spec.rb index 2f592fc054eef8eaf4122e7c91c6504a61459c07..4249a6af98c58d188832e0f5c7fb87e02d636046 100644 --- a/spec/models/poll_answer_spec.rb +++ b/spec/models/poll_answer_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe PollAnswer do +describe PollAnswer, :type => :model do before do @status = FactoryGirl.create(:status_message_with_poll) @user = alice @@ -9,9 +9,9 @@ describe PollAnswer do describe 'counter cache' do it 'increments the counter cache on the answer' do - lambda { + expect { alice.participate_in_poll!(@status, @answer) - }.should change{ + }.to change{ @answer.reload.vote_count }.by(1) end @@ -22,12 +22,12 @@ describe PollAnswer do it 'should validate pressence of answer' do answer = PollAnswer.new answer.valid? - answer.errors.should have_key(:answer) + expect(answer.errors).to have_key(:answer) end it 'answer should not empty' do answer = PollAnswer.new answer: ' ' answer.valid? - answer.errors.should have_key(:answer) + expect(answer.errors).to have_key(:answer) end end diff --git a/spec/models/poll_participation_spec.rb b/spec/models/poll_participation_spec.rb index 8f8819e8a785cfe9721fc9dc41a13c93c9161ffc..3caa16e2509ed8d4faef034a97a2162d95adbde8 100644 --- a/spec/models/poll_participation_spec.rb +++ b/spec/models/poll_participation_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require Rails.root.join("spec", "shared_behaviors", "relayable") -describe PollParticipation do +describe PollParticipation, :type => :model do before do @alices_aspect = alice.aspects.first @@ -44,19 +44,19 @@ describe PollParticipation do end it 'serializes the class name' do - @xml.include?(PollParticipation.name.underscore.to_s).should be true + expect(@xml.include?(PollParticipation.name.underscore.to_s)).to be true end it 'serializes the sender handle' do - @xml.include?(@poll_participation.diaspora_handle).should be true + expect(@xml.include?(@poll_participation.diaspora_handle)).to be true end it 'serializes the poll_guid' do - @xml.should include(@poll.guid) + expect(@xml).to include(@poll.guid) end it 'serializes the poll_answer_guid' do - @xml.should include(@poll_participation.poll_answer.guid) + expect(@xml).to include(@poll_participation.poll_answer.guid) end describe 'marshalling' do @@ -65,15 +65,15 @@ describe PollParticipation do end it 'marshals the author' do - @marshalled_poll_participation.author.should == @poll_participant.person + expect(@marshalled_poll_participation.author).to eq(@poll_participant.person) end it 'marshals the answer' do - @marshalled_poll_participation.poll_answer.should == @poll_participation.poll_answer + expect(@marshalled_poll_participation.poll_answer).to eq(@poll_participation.poll_answer) end it 'marshals the poll' do - @marshalled_poll_participation.poll.should == @poll + expect(@marshalled_poll_participation.poll).to eq(@poll) end end end @@ -94,8 +94,8 @@ describe PollParticipation do it 'is saved without errors in a simulated A-B node environment' do #stubs needed because the poll participation is already saved in the test db. This is just a simulated federation! - PollParticipation.any_instance.stub(:save!).and_return(true) - Person.any_instance.stub(:local?).and_return(false) + allow_any_instance_of(PollParticipation).to receive(:save!).and_return(true) + allow_any_instance_of(Person).to receive(:local?).and_return(false) expect{ salmon = Salmon::Slap.create_by_user_and_activity(alice, @poll_participation_alice.to_diaspora_xml).xml_for(@poll_participant) Postzord::Receiver::Public.new(salmon).save_object diff --git a/spec/models/poll_spec.rb b/spec/models/poll_spec.rb index 8970fe0ff2e777788a8feeba327863e24a369ffd..14e7af31a220554928c33c3bc70f1108d2f7ec09 100644 --- a/spec/models/poll_spec.rb +++ b/spec/models/poll_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Poll do +describe Poll, :type => :model do before do @poll = Poll.new(:question => "What do you think about apples?") end @@ -8,19 +8,19 @@ describe Poll do describe 'validation' do it 'should not create a poll when it has less than two answers' do @poll.poll_answers.build(:answer => '1') - @poll.should_not be_valid + expect(@poll).not_to be_valid end it 'should create a poll when it has more than two answers' do @poll.poll_answers.build(:answer => '1') @poll.poll_answers.build(:answer => '2') - @poll.should be_valid + expect(@poll).to be_valid end it 'should not create a poll when question in blank' do @poll.question = ' ' @poll.valid? - @poll.errors.should have_key(:question) + expect(@poll.errors).to have_key(:question) end end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index aa2cb29d6b23d01a4f68f648ccf77ea0aead6c73..14137d2a301f02fab7e89037d3fc14706d5b9110 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Post do +describe Post, :type => :model do before do @user = alice @aspect = @user.aspects.create(:name => "winners") @@ -21,29 +21,29 @@ describe Post do end it 'returns post from your contacts' do - StatusMessage.owned_or_visible_by_user(@you).should include(@post_from_contact) + expect(StatusMessage.owned_or_visible_by_user(@you)).to include(@post_from_contact) end it 'returns your posts' do - StatusMessage.owned_or_visible_by_user(@you).should include(@your_post) + expect(StatusMessage.owned_or_visible_by_user(@you)).to include(@your_post) end it 'returns public posts' do - StatusMessage.owned_or_visible_by_user(@you).should include(@public_post) + expect(StatusMessage.owned_or_visible_by_user(@you)).to include(@public_post) end it 'returns public post from your contact' do sm = FactoryGirl.create(:status_message, :author => eve.person, :public => true) - StatusMessage.owned_or_visible_by_user(@you).should include(sm) + expect(StatusMessage.owned_or_visible_by_user(@you)).to include(sm) end it 'does not return non contacts, non-public post' do - StatusMessage.owned_or_visible_by_user(@you).should_not include(@post_from_stranger) + expect(StatusMessage.owned_or_visible_by_user(@you)).not_to include(@post_from_stranger) end it 'should return the three visible posts' do - StatusMessage.owned_or_visible_by_user(@you).count(:all).should == 3 + expect(StatusMessage.owned_or_visible_by_user(@you).count(:all)).to eq(3) end end @@ -51,17 +51,17 @@ describe Post do describe '.for_a_stream' do it 'calls #for_visible_shareable_sql' do time, order = double, double - Post.should_receive(:for_visible_shareable_sql).with(time, order).and_return(Post) + expect(Post).to receive(:for_visible_shareable_sql).with(time, order).and_return(Post) Post.for_a_stream(time, order) end it 'calls includes_for_a_stream' do - Post.should_receive(:includes_for_a_stream) + expect(Post).to receive(:includes_for_a_stream) Post.for_a_stream(double, double) end it 'calls excluding_blocks if a user is present' do - Post.should_receive(:excluding_blocks).with(alice).and_return(Post) + expect(Post).to receive(:excluding_blocks).with(alice).and_return(Post) Post.for_a_stream(double, double, alice) end end @@ -75,15 +75,15 @@ describe Post do end it 'does not included blocked users posts' do - Post.excluding_blocks(bob).should_not include(@post) + expect(Post.excluding_blocks(bob)).not_to include(@post) end it 'includes not blocked users posts' do - Post.excluding_blocks(bob).should include(@other_post) + expect(Post.excluding_blocks(bob)).to include(@other_post) end it 'returns posts if you dont have any blocks' do - Post.excluding_blocks(alice).count.should == 2 + expect(Post.excluding_blocks(alice).count).to eq(2) end end @@ -94,17 +94,17 @@ describe Post do bob.toggle_hidden_shareable(@post) end it 'excludes posts the user has hidden' do - Post.excluding_hidden_shareables(bob).should_not include(@post) + expect(Post.excluding_hidden_shareables(bob)).not_to include(@post) end it 'includes posts the user has not hidden' do - Post.excluding_hidden_shareables(bob).should include(@other_post) + expect(Post.excluding_hidden_shareables(bob)).to include(@other_post) end end describe '.excluding_hidden_content' do it 'calls excluding_blocks and excluding_hidden_shareables' do - Post.should_receive(:excluding_blocks).and_return(Post) - Post.should_receive(:excluding_hidden_shareables) + expect(Post).to receive(:excluding_blocks).and_return(Post) + expect(Post).to receive(:excluding_hidden_shareables) Post.excluding_hidden_content(bob) end end @@ -127,8 +127,8 @@ describe Post do describe '.by_max_time' do it 'returns the posts ordered and limited by unix time' do - Post.for_a_stream(Time.now + 1, "created_at").should == @posts - Post.for_a_stream(Time.now + 1, "updated_at").should == @posts.reverse + expect(Post.for_a_stream(Time.now + 1, "created_at")).to eq(@posts) + expect(Post.for_a_stream(Time.now + 1, "updated_at")).to eq(@posts.reverse) end end @@ -136,15 +136,15 @@ describe Post do describe '.for_visible_shareable_sql' do it 'calls max_time' do time = Time.now + 1 - Post.should_receive(:by_max_time).with(time, 'created_at').and_return(Post) + expect(Post).to receive(:by_max_time).with(time, 'created_at').and_return(Post) Post.for_visible_shareable_sql(time, 'created_at') end it 'defaults to 15 posts' do chain = double.as_null_object - Post.stub(:by_max_time).and_return(chain) - chain.should_receive(:limit).with(15).and_return(Post) + allow(Post).to receive(:by_max_time).and_return(chain) + expect(chain).to receive(:limit).with(15).and_return(Post) Post.for_visible_shareable_sql(Time.now + 1, "created_at") end @@ -153,15 +153,15 @@ describe Post do # @posts[0] is the newest, @posts[5] is the oldest describe ".newer" do it 'returns the next post in the array' do - @posts[3].created_at.should < @posts[2].created_at #post 2 is newer - Post.newer(@posts[3]).created_at.to_s.should == @posts[2].created_at.to_s #its the newer post, not the newest + expect(@posts[3].created_at).to be < @posts[2].created_at #post 2 is newer + expect(Post.newer(@posts[3]).created_at.to_s).to eq(@posts[2].created_at.to_s) #its the newer post, not the newest end end describe ".older" do it 'returns the previous post in the array' do - Post.older(@posts[3]).created_at.to_s.should == @posts[4].created_at.to_s #its the older post, not the oldest - @posts[3].created_at.should > @posts[4].created_at #post 4 is older + expect(Post.older(@posts[3]).created_at.to_s).to eq(@posts[4].created_at.to_s) #its the older post, not the oldest + expect(@posts[3].created_at).to be > @posts[4].created_at #post 4 is older end end end @@ -170,14 +170,14 @@ describe Post do describe 'validations' do it 'validates uniqueness of guid and does not throw a db error' do message = FactoryGirl.create(:status_message) - FactoryGirl.build(:status_message, :guid => message.guid).should_not be_valid + expect(FactoryGirl.build(:status_message, :guid => message.guid)).not_to be_valid end end describe 'post_type' do it 'returns the class constant' do status_message = FactoryGirl.create(:status_message) - status_message.post_type.should == "StatusMessage" + expect(status_message.post_type).to eq("StatusMessage") end end @@ -186,8 +186,8 @@ describe Post do post = FactoryGirl.create(:status_message, :author => @user.person) @user.comment!(post, "hey") post.destroy - Post.where(:id => post.id).empty?.should == true - Comment.where(:text => "hey").empty?.should == true + expect(Post.where(:id => post.id).empty?).to eq(true) + expect(Comment.where(:text => "hey").empty?).to eq(true) end end @@ -196,22 +196,22 @@ describe Post do post = @user.post :status_message, :text => "hello", :to => @aspect.id xml = post.to_diaspora_xml - xml.include?("person_id").should be false - xml.include?(@user.person.diaspora_handle).should be true + expect(xml.include?("person_id")).to be false + expect(xml.include?(@user.person.diaspora_handle)).to be true end end describe '.diaspora_initialize' do it 'takes provider_display_name' do sm = FactoryGirl.create(:status_message, :provider_display_name => 'mobile') - StatusMessage.diaspora_initialize(sm.attributes.merge(:author => bob.person)).provider_display_name.should == 'mobile' + expect(StatusMessage.diaspora_initialize(sm.attributes.merge(:author => bob.person)).provider_display_name).to eq('mobile') end end describe '#mutable?' do it 'should be false by default' do post = @user.post :status_message, :text => "hello", :to => @aspect.id - post.mutable?.should == false + expect(post.mutable?).to eq(false) end end @@ -219,13 +219,13 @@ describe Post do it 'returns the people contained in the aspects the post appears in' do post = @user.post :status_message, :text => "hello", :to => @aspect.id - post.subscribers(@user).should == [] + expect(post.subscribers(@user)).to eq([]) end it 'returns all a users contacts if the post is public' do post = @user.post :status_message, :text => "hello", :to => @aspect.id, :public => true - post.subscribers(@user).to_set.should == @user.contact_people.to_set + expect(post.subscribers(@user).to_set).to eq(@user.contact_people.to_set) end end @@ -237,17 +237,17 @@ describe Post do it 'does not update updated_at' do old_time = Time.zone.now - 10000 Post.where(:id => @post.id).update_all(:updated_at => old_time) - @post.reload.updated_at.to_i.should == old_time.to_i + expect(@post.reload.updated_at.to_i).to eq(old_time.to_i) @post.update_likes_counter - @post.reload.updated_at.to_i.should == old_time.to_i + expect(@post.reload.updated_at.to_i).to eq(old_time.to_i) end end describe "#receive" do it 'returns false if the post does not verify' do @post = FactoryGirl.create(:status_message, :author => bob.person) - @post.should_receive(:verify_persisted_shareable).and_return(false) - @post.receive(bob, eve.person).should == false + expect(@post).to receive(:verify_persisted_shareable).and_return(false) + expect(@post.receive(bob, eve.person)).to eq(false) end end @@ -255,42 +255,42 @@ describe Post do before do @post = FactoryGirl.create(:status_message, :author => bob.person) @known_post = Post.new - bob.stub(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) + allow(bob).to receive(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) end context "user knows about the post" do before do - bob.stub(:find_visible_shareable_by_id).and_return(@known_post) + allow(bob).to receive(:find_visible_shareable_by_id).and_return(@known_post) end it 'updates attributes only if mutable' do - @known_post.stub(:mutable?).and_return(true) - @known_post.should_receive(:update_attributes) - @post.send(:receive_persisted, bob, eve.person, @known_post).should == true + allow(@known_post).to receive(:mutable?).and_return(true) + expect(@known_post).to receive(:update_attributes) + expect(@post.send(:receive_persisted, bob, eve.person, @known_post)).to eq(true) end it 'returns false if trying to update a non-mutable object' do - @known_post.stub(:mutable?).and_return(false) - @known_post.should_not_receive(:update_attributes) - @post.send(:receive_persisted, bob, eve.person, @known_post).should == false + allow(@known_post).to receive(:mutable?).and_return(false) + expect(@known_post).not_to receive(:update_attributes) + expect(@post.send(:receive_persisted, bob, eve.person, @known_post)).to eq(false) end end context "the user does not know about the post" do before do - bob.stub(:find_visible_shareable_by_id).and_return(nil) - bob.stub(:notify_if_mentioned).and_return(true) + allow(bob).to receive(:find_visible_shareable_by_id).and_return(nil) + allow(bob).to receive(:notify_if_mentioned).and_return(true) end it "receives the post from the contact of the author" do - @post.send(:receive_persisted, bob, eve.person, @known_post).should == true + expect(@post.send(:receive_persisted, bob, eve.person, @known_post)).to eq(true) end it 'notifies the user if they are mentioned' do - bob.stub(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) - bob.should_receive(:notify_if_mentioned).and_return(true) + allow(bob).to receive(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) + expect(bob).to receive(:notify_if_mentioned).and_return(true) - @post.send(:receive_persisted, bob, eve.person, @known_post).should == true + expect(@post.send(:receive_persisted, bob, eve.person, @known_post)).to eq(true) end end end @@ -299,25 +299,25 @@ describe Post do context "the user does not know about the post" do before do @post = FactoryGirl.create(:status_message, :author => bob.person) - bob.stub(:find_visible_shareable_by_id).and_return(nil) - bob.stub(:notify_if_mentioned).and_return(true) + allow(bob).to receive(:find_visible_shareable_by_id).and_return(nil) + allow(bob).to receive(:notify_if_mentioned).and_return(true) end it "it receives the post from the contact of the author" do - bob.should_receive(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) - @post.send(:receive_non_persisted, bob, eve.person).should == true + expect(bob).to receive(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) + expect(@post.send(:receive_non_persisted, bob, eve.person)).to eq(true) end it 'notifies the user if they are mentioned' do - bob.stub(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) - bob.should_receive(:notify_if_mentioned).and_return(true) + allow(bob).to receive(:contact_for).with(eve.person).and_return(double(:receive_shareable => true)) + expect(bob).to receive(:notify_if_mentioned).and_return(true) - @post.send(:receive_non_persisted, bob, eve.person).should == true + expect(@post.send(:receive_non_persisted, bob, eve.person)).to eq(true) end it 'returns false if the post does not save' do - @post.stub(:save).and_return(false) - @post.send(:receive_non_persisted, bob, eve.person).should == false + allow(@post).to receive(:save).and_return(false) + expect(@post.send(:receive_non_persisted, bob, eve.person)).to eq(false) end end end @@ -325,40 +325,40 @@ describe Post do describe '#reshares_count' do before :each do @post = @user.post :status_message, :text => "hello", :to => @aspect.id, :public => true - @post.reshares.size.should == 0 + expect(@post.reshares.size).to eq(0) end describe 'when post has not been reshared' do it 'returns zero' do - @post.reshares_count.should == 0 + expect(@post.reshares_count).to eq(0) end end describe 'when post has been reshared exactly 1 time' do before :each do - @post.reshares.size.should == 0 + expect(@post.reshares.size).to eq(0) @reshare = FactoryGirl.create(:reshare, :root => @post) @post.reload - @post.reshares.size.should == 1 + expect(@post.reshares.size).to eq(1) end it 'returns 1' do - @post.reshares_count.should == 1 + expect(@post.reshares_count).to eq(1) end end describe 'when post has been reshared more than once' do before :each do - @post.reshares.size.should == 0 + expect(@post.reshares.size).to eq(0) FactoryGirl.create(:reshare, :root => @post) FactoryGirl.create(:reshare, :root => @post) FactoryGirl.create(:reshare, :root => @post) @post.reload - @post.reshares.size.should == 3 + expect(@post.reshares.size).to eq(3) end it 'returns the number of reshares' do - @post.reshares_count.should == 3 + expect(@post.reshares_count).to eq(3) end end end @@ -366,25 +366,25 @@ describe Post do describe "#after_create" do it "sets #interacted_at" do post = FactoryGirl.create(:status_message) - post.interacted_at.should_not be_blank + expect(post.interacted_at).not_to be_blank end end describe "#find_by_guid_or_id_with_user" do it "succeeds with an id" do post = FactoryGirl.create :status_message, public: true - Post.find_by_guid_or_id_with_user(post.id).should == post + expect(Post.find_by_guid_or_id_with_user(post.id)).to eq(post) end it "succeeds with an guid" do post = FactoryGirl.create :status_message, public: true - Post.find_by_guid_or_id_with_user(post.guid).should == post + expect(Post.find_by_guid_or_id_with_user(post.guid)).to eq(post) end it "looks up on the passed user object if it's non-nil" do post = FactoryGirl.create :status_message user = double - user.should_receive(:find_visible_shareable_by_id).with(Post, post.id, key: :id).and_return(post) + expect(user).to receive(:find_visible_shareable_by_id).with(Post, post.id, key: :id).and_return(post) Post.find_by_guid_or_id_with_user post.id, user end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 4d152589d1447550c360ad2ec0799efda500102f..b9406c5f3d7270c47c5c0a26306e86baad1d408e 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -4,28 +4,28 @@ require 'spec_helper' -describe Profile do +describe Profile, :type => :model do describe 'validation' do describe "of first_name" do it "strips leading and trailing whitespace" do profile = FactoryGirl.build(:profile, :first_name => " Shelly ") - profile.should be_valid - profile.first_name.should == "Shelly" + expect(profile).to be_valid + expect(profile.first_name).to eq("Shelly") end it "can be 32 characters long" do profile = FactoryGirl.build(:profile, :first_name => "Hexagoooooooooooooooooooooooooon") - profile.should be_valid + expect(profile).to be_valid end it "cannot be 33 characters" do profile = FactoryGirl.build(:profile, :first_name => "Hexagooooooooooooooooooooooooooon") - profile.should_not be_valid + expect(profile).not_to be_valid end it 'cannot have ;' do profile = FactoryGirl.build(:profile, :first_name => "Hex;agon") - profile.should_not be_valid + expect(profile).not_to be_valid end end @@ -36,19 +36,19 @@ describe Profile do it 'outputs a hash that can update a diaspora profile' do profile = Profile.new - profile.from_omniauth_hash(@from_omniauth)['bio'].should == 'this is my bio' + expect(profile.from_omniauth_hash(@from_omniauth)['bio']).to eq('this is my bio') end it 'does not overwrite any exsisting profile fields' do profile = Profile.new(:first_name => 'maxwell') - profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'maxwell' + expect(profile.from_omniauth_hash(@from_omniauth)['first_name']).to eq('maxwell') end it 'sets full name to first name' do @from_omniauth = {'name' => 'bob jones', 'description' => 'this is my bio', 'location' => 'sf', 'image' => 'http://cats.com/gif.gif'} profile = Profile.new - profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'bob jones' + expect(profile.from_omniauth_hash(@from_omniauth)['first_name']).to eq('bob jones') end end @@ -58,9 +58,9 @@ describe Profile do profile.first_name = "casimiro" profile.last_name = nil - profile.full_name.should_not == "casimiro" + expect(profile.full_name).not_to eq("casimiro") profile.save - profile.full_name.should == "casimiro" + expect(profile.full_name).to eq("casimiro") end it 'generates a full name given only last name' do @@ -68,9 +68,9 @@ describe Profile do profile.first_name = nil profile.last_name = "grippi" - profile.full_name.should_not == "grippi" + expect(profile.full_name).not_to eq("grippi") profile.save - profile.full_name.should == "grippi" + expect(profile.full_name).to eq("grippi") end it 'generates a full name given first and last names' do @@ -78,36 +78,36 @@ describe Profile do profile.first_name = "casimiro" profile.last_name = "grippi" - profile.full_name.should_not == "casimiro grippi" + expect(profile.full_name).not_to eq("casimiro grippi") profile.save - profile.full_name.should == "casimiro grippi" + expect(profile.full_name).to eq("casimiro grippi") end end describe "of last_name" do it "strips leading and trailing whitespace" do profile = FactoryGirl.build(:profile, :last_name => " Ohba ") - profile.should be_valid - profile.last_name.should == "Ohba" + expect(profile).to be_valid + expect(profile.last_name).to eq("Ohba") end it "can be 32 characters long" do profile = FactoryGirl.build(:profile, :last_name => "Hexagoooooooooooooooooooooooooon") - profile.should be_valid + expect(profile).to be_valid end it "cannot be 33 characters" do profile = FactoryGirl.build(:profile, :last_name => "Hexagooooooooooooooooooooooooooon") - profile.should_not be_valid + expect(profile).not_to be_valid end it 'cannot have ;' do profile = FactoryGirl.build(:profile, :last_name => "Hex;agon") - profile.should_not be_valid + expect(profile).not_to be_valid end it 'disallows ; with a newline in the string' do profile = FactoryGirl.build(:profile, :last_name => "H\nex;agon") - profile.should_not be_valid + expect(profile).not_to be_valid end end end @@ -120,17 +120,17 @@ describe Profile do end it 'ignores an empty string' do - lambda {@profile.image_url = ""}.should_not change(@profile, :image_url) + expect {@profile.image_url = ""}.not_to change(@profile, :image_url) end it 'makes relative urls absolute' do @profile.image_url = "/relative/url" - @profile.image_url.should == "#{@pod_url}/relative/url" + expect(@profile.image_url).to eq("#{@pod_url}/relative/url") end it "doesn't change absolute urls" do @profile.image_url = "http://not/a/relative/url" - @profile.image_url.should == "http://not/a/relative/url" + expect(@profile.image_url).to eq("http://not/a/relative/url") end end @@ -141,8 +141,8 @@ describe Profile do xml = @profile.to_xml new_profile = Profile.from_xml(xml.to_s) - new_profile.tag_string.should_not be_blank - new_profile.tag_string.should include('#rafi') + expect(new_profile.tag_string).not_to be_blank + expect(new_profile.tag_string).to include('#rafi') end end @@ -151,7 +151,7 @@ describe Profile do it 'should include persons diaspora handle' do xml = person.profile.to_diaspora_xml - xml.should include "foobar" + expect(xml).to include "foobar" end it 'includes tags' do @@ -159,14 +159,14 @@ describe Profile do person.profile.build_tags person.profile.save xml = person.profile.to_diaspora_xml - xml.should include "#one" + expect(xml).to include "#one" end it 'includes location' do person.profile.location = 'Dark Side, Moon' person.profile.save xml = person.profile.to_diaspora_xml - xml.should include "Dark Side, Moon" + expect(xml).to include "Dark Side, Moon" end end @@ -177,7 +177,7 @@ describe Profile do it 'returns a default rather than nil' do @profile.image_url = nil - @profile.image_url.should_not be_nil + expect(@profile.image_url).not_to be_nil end it 'falls back to the large thumbnail if the small thumbnail is nil' do @@ -185,14 +185,14 @@ describe Profile do @profile[:image_url] = 'large' @profile[:image_url_small] = nil @profile[:image_url_medium] = nil - @profile.image_url(:thumb_small).should == 'large' - @profile.image_url(:thumb_medium).should == 'large' + expect(@profile.image_url(:thumb_small)).to eq('large') + expect(@profile.image_url(:thumb_medium)).to eq('large') end end describe '#subscribers' do it 'returns all non-pending contacts for a user' do - bob.profile.subscribers(bob).map{|s| s.id}.should =~ [alice.person, eve.person].map{|s| s.id} + expect(bob.profile.subscribers(bob).map{|s| s.id}).to match_array([alice.person, eve.person].map{|s| s.id}) end end @@ -202,43 +202,43 @@ describe Profile do it 'accepts form data' do profile.birthday = nil profile.date = { 'year' => '2000', 'month' => '01', 'day' => '01' } - profile.birthday.year.should == 2000 - profile.birthday.month.should == 1 - profile.birthday.day.should == 1 + expect(profile.birthday.year).to eq(2000) + expect(profile.birthday.month).to eq(1) + expect(profile.birthday.day).to eq(1) end it 'unsets the birthday' do profile.birthday = Date.new(2000, 1, 1) profile.date = { 'year' => '', 'month' => '', 'day' => ''} - profile.birthday.should == nil + expect(profile.birthday).to eq(nil) end it 'does not change with blank month and day values' do profile.birthday = Date.new(2000, 1, 1) profile.date = { 'year' => '2001', 'month' => '', 'day' => ''} - profile.birthday.year.should == 2000 - profile.birthday.month.should == 1 - profile.birthday.day.should == 1 + expect(profile.birthday.year).to eq(2000) + expect(profile.birthday.month).to eq(1) + expect(profile.birthday.day).to eq(1) end it 'does not accept blank initial values' do profile.birthday = nil profile.date = { 'year' => '2001', 'month' => '', 'day' => ''} - profile.birthday.should == nil + expect(profile.birthday).to eq(nil) end it 'does not accept invalid dates' do profile.birthday = nil profile.date = { 'year' => '2001', 'month' => '02', 'day' => '31' } - profile.birthday.should == nil + expect(profile.birthday).to eq(nil) end it 'does not change with invalid dates' do profile.birthday = Date.new(2000, 1, 1) profile.date = { 'year' => '2001', 'month' => '02', 'day' => '31' } - profile.birthday.year.should == 2000 - profile.birthday.month.should == 1 - profile.birthday.day.should == 1 + expect(profile.birthday.year).to eq(2000) + expect(profile.birthday.month).to eq(1) + expect(profile.birthday.day).to eq(1) end end @@ -253,12 +253,12 @@ describe Profile do @object.valid? @object.errors.full_messages - @object.should be_valid + expect(@object).to be_valid end it 'strips more than 5 tags' do @object.tag_string = '#one #two #three #four #five #six' @object.save - @object.tags.count.should == 5 + expect(@object.tags.count).to eq(5) end it_should_behave_like 'it is taggable' end @@ -271,18 +271,18 @@ describe Profile do end it 'returns a formatted date' do - @profile.formatted_birthday.should == "January 1, 2000" + expect(@profile.formatted_birthday).to eq("January 1, 2000") end it 'removes nil year birthdays' do @profile_hash.delete('year') @profile.date = @profile_hash - @profile.formatted_birthday.should == 'January 1' + expect(@profile.formatted_birthday).to eq('January 1') end it 'retuns nil if no birthday is set' do @profile.date = {} - @profile.formatted_birthday.should == nil + expect(@profile.formatted_birthday).to eq(nil) end end @@ -291,10 +291,10 @@ describe Profile do it 'updates the profile in place' do local_luke, local_leia, remote_raphael = set_up_friends new_profile = FactoryGirl.build :profile - lambda{ + expect{ new_profile.receive(local_leia, remote_raphael) - }.should_not change(Profile, :count) - remote_raphael.last_name.should == new_profile.last_name + }.not_to change(Profile, :count) + expect(remote_raphael.last_name).to eq(new_profile.last_name) end end @@ -309,12 +309,12 @@ describe Profile do @profile.tombstone! @profile.reload attributes.each{ |attr| - @profile[attr.to_sym].should be_blank + expect(@profile[attr.to_sym]).to be_blank } end it 'removes all the tags from the profile' do - @profile.taggings.should_receive(:delete_all) + expect(@profile.taggings).to receive(:delete_all) @profile.tombstone! end end @@ -322,7 +322,7 @@ describe Profile do describe "#clearable_fields" do it 'returns the current profile fields' do profile = FactoryGirl.build :profile - profile.send(:clearable_fields).sort.should == + expect(profile.send(:clearable_fields).sort).to eq( ["diaspora_handle", "first_name", "last_name", @@ -336,6 +336,7 @@ describe Profile do "nsfw", "location", "full_name"].sort + ) end end end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 3595a6a1a0f7cc3c9315c62945f30b0337cb4d74..7bbce6502fab0a8e745ff6a033f9d060166a48ab 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe Report do +describe Report, :type => :model do before do #:report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' } @user = bob @@ -27,34 +27,34 @@ describe Report do it 'validates that post ID is required' do report = @valid_post_report report.delete(:item_id) - @user.reports.build(report).should_not be_valid + expect(@user.reports.build(report)).not_to be_valid end it 'validates that post type is required' do report = @valid_post_report report.delete(:item_type) - @user.reports.build(report).should_not be_valid + expect(@user.reports.build(report)).not_to be_valid end it 'validates that post does exist' do report = @valid_post_report report[:item_id] = 666; - @user.reports.build(report).should_not be_valid + expect(@user.reports.build(report)).not_to be_valid end it 'validates that comment does exist' do report = @valid_comment_report report[:item_id] = 666; - @user.reports.build(report).should_not be_valid + expect(@user.reports.build(report)).not_to be_valid end it 'validates that entry does not exist' do - @user.reports.build(@valid_post_report).should be_valid + expect(@user.reports.build(@valid_post_report)).to be_valid end it 'validates that entry does exist' do @user.reports.create(@valid_post_report) - @user.reports.build(@valid_post_report).should_not be_valid + expect(@user.reports.build(@valid_post_report)).not_to be_valid end end diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index e82613cb5de02661e04ce2f5452cfe93f9386a83..89dfd85f6608f167a387b1988cdcfda4d6f4ec2d 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' -describe Reshare do +describe Reshare, :type => :model do include Rails.application.routes.url_helpers it 'has a valid Factory' do - FactoryGirl.build(:reshare).should be_valid + expect(FactoryGirl.build(:reshare)).to be_valid end it 'requires root' do reshare = FactoryGirl.build(:reshare, :root => nil) - reshare.should_not be_valid + expect(reshare).not_to be_valid end it 'require public root' do reshare = FactoryGirl.build(:reshare, :root => FactoryGirl.create(:status_message, :public => false)) - reshare.should_not be_valid - reshare.errors[:base].should include('Only posts which are public may be reshared.') + expect(reshare).not_to be_valid + expect(reshare.errors[:base]).to include('Only posts which are public may be reshared.') end it 'forces public' do - FactoryGirl.create(:reshare, :public => false).public.should be true + expect(FactoryGirl.create(:reshare, :public => false).public).to be true end describe "#receive" do @@ -32,20 +32,20 @@ describe Reshare do it 'increments the reshare count' do receive_reshare - @root.resharers.count.should == 1 + expect(@root.resharers.count).to eq(1) end it 'adds the resharer to the re-sharers of the post' do receive_reshare - @root.resharers.should include(@reshare.author) + expect(@root.resharers).to include(@reshare.author) end it 'does not error if the root author has a contact for the resharer' do bob.share_with @reshare.author, bob.aspects.first - proc { + expect { Timeout.timeout(5) do receive_reshare #This doesn't ever terminate on my machine before it was fixed. end - }.should_not raise_error + }.not_to raise_error end end @@ -58,8 +58,8 @@ describe Reshare do end it 'deletates #nsfw to the root post' do - @sfw_reshare.nsfw.should_not be true - @nsfw_reshare.nsfw.should be_truthy + expect(@sfw_reshare.nsfw).not_to be true + expect(@nsfw_reshare.nsfw).to be_truthy end end @@ -69,11 +69,11 @@ describe Reshare do @reshare = FactoryGirl.build(:reshare, :root => sm) end it 'does not return anything for non-author of the original post' do - @reshare.notification_type(bob, @reshare.author).should be_nil + expect(@reshare.notification_type(bob, @reshare.author)).to be_nil end it 'returns "Reshared" for the original post author' do - @reshare.notification_type(alice, @reshare.author).should == Notifications::Reshared + expect(@reshare.notification_type(alice, @reshare.author)).to eq(Notifications::Reshared) end end @@ -92,7 +92,7 @@ describe Reshare do end it 'resolves root posts to the top level' do - @rs3.absolute_root.should == @sm + expect(@rs3.absolute_root).to eq(@sm) end it 'can handle deleted reshares' do @@ -125,13 +125,13 @@ describe Reshare do context 'serialization' do it 'serializes root_diaspora_id' do - @xml.should include("root_diaspora_id") - @xml.should include(@reshare.author.diaspora_handle) + expect(@xml).to include("root_diaspora_id") + expect(@xml).to include(@reshare.author.diaspora_handle) end it 'serializes root_guid' do - @xml.should include("root_guid") - @xml.should include(@reshare.root.guid) + expect(@xml).to include("root_guid") + expect(@xml).to include(@reshare.root.guid) end end @@ -143,15 +143,15 @@ describe Reshare do end it 'marshals the guid' do - Reshare.from_xml(@xml).root_guid.should == @root_object.guid + expect(Reshare.from_xml(@xml).root_guid).to eq(@root_object.guid) end it 'fetches the root post from root_guid' do - Reshare.from_xml(@xml).root.should == @root_object + expect(Reshare.from_xml(@xml).root).to eq(@root_object) end it 'fetches the root author from root_diaspora_id' do - Reshare.from_xml(@xml).root.author.should == @original_author + expect(Reshare.from_xml(@xml).root.author).to eq(@original_author) end end @@ -171,8 +171,8 @@ describe Reshare do @root_object = @reshare.root @root_object.delete @response = double - @response.stub(:status).and_return(200) - @response.stub(:success?).and_return(true) + allow(@response).to receive(:status).and_return(200) + allow(@response).to receive(:success?).and_return(true) end it 'fetches the root author from root_diaspora_id' do @@ -184,19 +184,19 @@ describe Reshare do @original_author.profile = @original_profile wf_prof_double = double - wf_prof_double.should_receive(:fetch).and_return(@original_author) - Webfinger.should_receive(:new).and_return(wf_prof_double) + expect(wf_prof_double).to receive(:fetch).and_return(@original_author) + expect(Webfinger).to receive(:new).and_return(wf_prof_double) - @response.stub(:body).and_return(@root_object.to_diaspora_xml) + allow(@response).to receive(:body).and_return(@root_object.to_diaspora_xml) - Faraday.default_connection.should_receive(:get).with(@original_author.url + short_post_path(@root_object.guid, :format => "xml")).and_return(@response) + expect(Faraday.default_connection).to receive(:get).with(@original_author.url + short_post_path(@root_object.guid, :format => "xml")).and_return(@response) Reshare.from_xml(@xml) end context "fetching post" do it "doesn't error out if the post is not found" do - @response.stub(:status).and_return(404) - Faraday.default_connection.should_receive(:get).and_return(@response) + allow(@response).to receive(:status).and_return(404) + expect(Faraday.default_connection).to receive(:get).and_return(@response) expect { Reshare.from_xml(@xml) @@ -204,9 +204,9 @@ describe Reshare do end it "raises if there's another error receiving the post" do - @response.stub(:status).and_return(500) - @response.stub(:success?).and_return(false) - Faraday.default_connection.should_receive(:get).and_return(@response) + allow(@response).to receive(:status).and_return(500) + allow(@response).to receive(:success?).and_return(false) + expect(Faraday.default_connection).to receive(:get).and_return(@response) expect { Reshare.from_xml(@xml) @@ -216,25 +216,25 @@ describe Reshare do context 'saving the post' do before do - @response.stub(:body).and_return(@root_object.to_diaspora_xml) - Faraday.default_connection.stub(:get).with(@reshare.root.author.url + short_post_path(@root_object.guid, :format => "xml")).and_return(@response) + allow(@response).to receive(:body).and_return(@root_object.to_diaspora_xml) + allow(Faraday.default_connection).to receive(:get).with(@reshare.root.author.url + short_post_path(@root_object.guid, :format => "xml")).and_return(@response) end it 'fetches the root post from root_guid' do root = Reshare.from_xml(@xml).root [:text, :guid, :diaspora_handle, :type, :public].each do |attr| - root.send(attr).should == @reshare.root.send(attr) + expect(root.send(attr)).to eq(@reshare.root.send(attr)) end end it 'correctly saves the type' do - Reshare.from_xml(@xml).root.reload.type.should == "StatusMessage" + expect(Reshare.from_xml(@xml).root.reload.type).to eq("StatusMessage") end it 'correctly sets the author' do @original_author = @reshare.root.author - Reshare.from_xml(@xml).root.reload.author.reload.should == @original_author + expect(Reshare.from_xml(@xml).root.reload.author.reload).to eq(@original_author) end it 'verifies that the author of the post received is the same as the author in the reshare xml' do @@ -244,14 +244,14 @@ describe Reshare do different_person = FactoryGirl.build(:person) wf_prof_double = double - wf_prof_double.should_receive(:fetch).and_return(different_person) - Webfinger.should_receive(:new).and_return(wf_prof_double) + expect(wf_prof_double).to receive(:fetch).and_return(different_person) + expect(Webfinger).to receive(:new).and_return(wf_prof_double) - different_person.stub(:url).and_return(@original_author.url) + allow(different_person).to receive(:url).and_return(@original_author.url) - lambda{ + expect{ Reshare.from_xml(@xml) - }.should raise_error /^Diaspora ID \(.+\) in the root does not match the Diaspora ID \(.+\) specified in the reshare!$/ + }.to raise_error /^Diaspora ID \(.+\) in the root does not match the Diaspora ID \(.+\) specified in the reshare!$/ end end end diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 23a3e742c75a281fadf975c7ec07a1f5758b2ce3..59ddaeb60939ace6ed1ec3dd5e2aecd7c5e0e6ba 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe Role do +describe Role, :type => :model do skip "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 069c8811a0386d6000ba15237f6f272870cf7753..a7aa8a3e6bcfac1c3ed66937b5fd3891c6c47ee5 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Service do +describe Service, :type => :model do before do @post = alice.post(:status_message, :text => "hello", :to => alice.aspects.first.id) @@ -15,7 +15,7 @@ describe Service do alice.services << second_service alice.services.last.save - alice.services.last.should be_invalid + expect(alice.services.last).to be_invalid end it 'by default has no profile photo url' do diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index fb2a7f8545c4523d9c26937f812089a63d71c4ac..adb4fc8bcada6f89c114c768cfc88b5a8ec97e78 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Services::Facebook do +describe Services::Facebook, :type => :model do before do @user = alice @@ -26,7 +26,7 @@ describe Services::Facebook do it 'removes text formatting markdown from post text' do message = double - message.should_receive(:plain_text_without_markdown).and_return("") + expect(message).to receive(:plain_text_without_markdown).and_return("") post = double(message: message, photos: []) post_params = @service.create_post_params(post) end @@ -35,14 +35,14 @@ describe Services::Facebook do message = "Some text." post = double(message: double(plain_text_without_markdown: message), photos: []) post_params = @service.create_post_params(post) - post_params[:message].should_not include "http" + expect(post_params[:message]).not_to include "http" end it 'sets facebook id on post' do stub_request(:post, "https://graph.facebook.com/me/feed"). to_return(:status => 200, :body => '{"id": "12345"}', :headers => {}) @service.post(@post) - @post.facebook_id.should match "12345" + expect(@post.facebook_id).to match "12345" end end @@ -63,7 +63,7 @@ describe Services::Facebook do it "should include post url in message with photos" do post_params = @service.create_post_params(@status_message) - post_params[:message].should include 'http' + expect(post_params[:message]).to include 'http' end end @@ -72,8 +72,9 @@ describe Services::Facebook do it 'returns a large profile photo url' do @service.uid = "abc123" @service.access_token = "token123" - @service.profile_photo_url.should == + expect(@service.profile_photo_url).to eq( "https://graph.facebook.com/abc123/picture?type=large&access_token=token123" + ) end end @@ -82,7 +83,7 @@ describe Services::Facebook do @post.facebook_id = "2345" url="https://graph.facebook.com/#{@post.facebook_id}/" stub_request(:delete, "#{url}?access_token=#{@service.access_token}").to_return(:status => 200) - @service.should_receive(:delete_from_facebook).with(url, {access_token: @service.access_token}) + expect(@service).to receive(:delete_from_facebook).with(url, {access_token: @service.access_token}) @service.delete_post(@post) end diff --git a/spec/models/services/tumblr_spec.rb b/spec/models/services/tumblr_spec.rb index f60c2c32a9f6889d20f15c02fffcd0f07defa0e1..c6ecb9c3e7a53f2b37b19825832d99c455076724 100644 --- a/spec/models/services/tumblr_spec.rb +++ b/spec/models/services/tumblr_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Services::Tumblr do +describe Services::Tumblr, :type => :model do before do @user = alice @@ -12,16 +12,16 @@ describe Services::Tumblr do describe '#post' do it 'posts a status message to tumblr and saves the returned ids' do response = double(body: '{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}') - OAuth::AccessToken.any_instance.should_receive(:get) + expect_any_instance_of(OAuth::AccessToken).to receive(:get) .with("/v2/user/info") .and_return(response) response = double(code: "201", body: '{"response": {"id": "bla"}}') - OAuth::AccessToken.any_instance.should_receive(:post) + expect_any_instance_of(OAuth::AccessToken).to receive(:post) .with("/v2/blog/foo.tumblr.com/post", @service.build_tumblr_post(@post, '')) .and_return(response) - @post.should_receive(:tumblr_ids=).with({"foo.tumblr.com" => "bla"}.to_json) + expect(@post).to receive(:tumblr_ids=).with({"foo.tumblr.com" => "bla"}.to_json) @service.post(@post) end diff --git a/spec/models/services/twitter_spec.rb b/spec/models/services/twitter_spec.rb index 351c8d6eff806e702758e18b518effba8ab8dcc9..c111f6c3472db60913635adf95fe17feade9155f 100644 --- a/spec/models/services/twitter_spec.rb +++ b/spec/models/services/twitter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Services::Twitter do +describe Services::Twitter, :type => :model do before do @user = alice @@ -12,34 +12,34 @@ describe Services::Twitter do describe '#post' do before do - Twitter::Client.any_instance.stub(:update) { Twitter::Tweet.new(id: "1234") } + allow_any_instance_of(Twitter::Client).to receive(:update) { Twitter::Tweet.new(id: "1234") } end it 'posts a status message to twitter' do - Twitter::Client.any_instance.should_receive(:update).with(instance_of(String)) + expect_any_instance_of(Twitter::Client).to receive(:update).with(instance_of(String)) @service.post(@post) end it 'sets the tweet_id on the post' do @service.post(@post) - @post.tweet_id.should match "1234" + expect(@post.tweet_id).to match "1234" end it 'swallows exception raised by twitter always being down' do skip - Twitter::Client.any_instance.should_receive(:update).and_raise(StandardError) + expect_any_instance_of(Twitter::Client).to receive(:update).and_raise(StandardError) @service.post(@post) end it 'should call build_twitter_post' do url = "foo" - @service.should_receive(:build_twitter_post).with(@post, 0) + expect(@service).to receive(:build_twitter_post).with(@post, 0) @service.post(@post, url) end it 'removes text formatting markdown from post text' do message = double - message.should_receive(:plain_text_without_markdown).and_return("") + expect(message).to receive(:plain_text_without_markdown).and_return("") post = double(message: message, photos: []) @service.send(:build_twitter_post, post) end @@ -55,13 +55,13 @@ describe Services::Twitter do it "should not truncate a short message" do short_message = SecureRandom.hex(20) short_post = double(message: double(plain_text_without_markdown: short_message), photos: []) - @service.send(:build_twitter_post, short_post).should match short_message + expect(@service.send(:build_twitter_post, short_post)).to match short_message end it "should truncate a long message" do long_message = SecureRandom.hex(220) long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) - @service.send(:build_twitter_post, long_post).length.should be < long_message.length + expect(@service.send(:build_twitter_post, long_post).length).to be < long_message.length end it "should not truncate a long message with an http url" do @@ -70,7 +70,7 @@ describe Services::Twitter do @post.text = long_message answer = @service.send(:build_twitter_post, @post) - answer.should_not match /\.\.\./ + expect(answer).not_to match /\.\.\./ end it "should not cut links when truncating a post" do @@ -78,8 +78,8 @@ describe Services::Twitter do long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) answer = @service.send(:build_twitter_post, long_post) - answer.should match /\.\.\./ - answer.should match /shortened\.html/ + expect(answer).to match /\.\.\./ + expect(answer).to match /shortened\.html/ end it "should append the otherwise-cut link when truncating a post" do @@ -87,15 +87,15 @@ describe Services::Twitter do long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) answer = @service.send(:build_twitter_post, long_post) - answer.should match /\.\.\./ - answer.should match /shortened\.html/ + expect(answer).to match /\.\.\./ + expect(answer).to match /shortened\.html/ end it "should not truncate a long message with an https url" do long_message = " https://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + @long_message_end @post.text = long_message answer = @service.send(:build_twitter_post, @post) - answer.should_not match /\.\.\./ + expect(answer).not_to match /\.\.\./ end it "should truncate a long message with an ftp url" do @@ -103,7 +103,7 @@ describe Services::Twitter do long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) answer = @service.send(:build_twitter_post, long_post) - answer.should match /\.\.\./ + expect(answer).to match /\.\.\./ end it "should not truncate a message of maximum length" do @@ -111,7 +111,7 @@ describe Services::Twitter do exact_size_post = double(message: double(plain_text_without_markdown: exact_size_message), id: 1, photos: []) answer = @service.send(:build_twitter_post, exact_size_post) - answer.should match exact_size_message + expect(answer).to match exact_size_message end end @@ -132,7 +132,7 @@ describe Services::Twitter do it "should include post url in short message with photos" do answer = @service.send(:build_twitter_post, @status_message) - answer.should include 'http' + expect(answer).to include 'http' end end @@ -140,11 +140,11 @@ describe Services::Twitter do describe "#profile_photo_url" do it 'returns the original profile photo url' do user_double = double - user_double.should_receive(:profile_image_url_https).with("original").and_return("http://a2.twimg.com/profile_images/uid/avatar.png") - Twitter::Client.any_instance.should_receive(:user).with("joindiaspora").and_return(user_double) + expect(user_double).to receive(:profile_image_url_https).with("original").and_return("http://a2.twimg.com/profile_images/uid/avatar.png") + expect_any_instance_of(Twitter::Client).to receive(:user).with("joindiaspora").and_return(user_double) @service.nickname = "joindiaspora" - @service.profile_photo_url.should == "http://a2.twimg.com/profile_images/uid/avatar.png" + expect(@service.profile_photo_url).to eq("http://a2.twimg.com/profile_images/uid/avatar.png") end end end diff --git a/spec/models/services/wordpress_spec.rb b/spec/models/services/wordpress_spec.rb index fd970d839fb2435febcd4cdc8de98b432be95ef1..94528597946a871d7518f896a1f43a26cac32b74 100644 --- a/spec/models/services/wordpress_spec.rb +++ b/spec/models/services/wordpress_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Services::Wordpress do +describe Services::Wordpress, :type => :model do before do @user = alice @@ -23,10 +23,10 @@ describe Services::Wordpress do describe "#post_body" do it "truncates content for use in title" do - @service.post_body(@post)[:title].should eq("Hello there. This is a Wordpress post...") + expect(@service.post_body(@post)[:title]).to eq("Hello there. This is a Wordpress post...") end it "converts markdown tags" do - @service.post_body(@post)[:content].should match("<strong>Wordpress</strong>") + expect(@service.post_body(@post)[:content]).to match("<strong>Wordpress</strong>") end end diff --git a/spec/models/share_visibility_spec.rb b/spec/models/share_visibility_spec.rb index d93a42d20c05ca6a9344f45e886821a8551aba9c..fe2674fe3a525c4dff464470ad816d0f3bbcba34 100644 --- a/spec/models/share_visibility_spec.rb +++ b/spec/models/share_visibility_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe ShareVisibility do +describe ShareVisibility, :type => :model do describe '.batch_import' do before do @post = FactoryGirl.create(:status_message, :author => alice.person) @@ -14,22 +14,22 @@ describe ShareVisibility do it 'returns false if share is public' do @post.public = true @post.save - ShareVisibility.batch_import([@contact.id], @post).should be false + expect(ShareVisibility.batch_import([@contact.id], @post)).to be false end it 'creates a visibility for each user' do - lambda { + expect { ShareVisibility.batch_import([@contact.id], @post) - }.should change { + }.to change { ShareVisibility.exists?(:contact_id => @contact.id, :shareable_id => @post.id, :shareable_type => 'Post') }.from(false).to(true) end it 'does not raise if a visibility already exists' do ShareVisibility.create!(:contact_id => @contact.id, :shareable_id => @post.id, :shareable_type => 'Post') - lambda { + expect { ShareVisibility.batch_import([@contact.id], @post) - }.should_not raise_error + }.not_to raise_error end context "scopes" do @@ -40,7 +40,7 @@ describe ShareVisibility do it 'searches for share visibilies for all users contacts' do contact_ids = alice.contacts.map(&:id) - ShareVisibility.for_a_users_contacts(alice).should == ShareVisibility.where(:contact_id => contact_ids).to_a + expect(ShareVisibility.for_a_users_contacts(alice)).to eq(ShareVisibility.where(:contact_id => contact_ids).to_a) end end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index e91677f30f0254b4b7c37d2dc4dccec1e8d36617..28c0411be346ad79324ef0e03b59b21be0dc372c 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe StatusMessage do +describe StatusMessage, :type => :model do include PeopleHelper before do @@ -22,7 +22,7 @@ describe StatusMessage do FactoryGirl.create(:status_message, :text => @test_string ) FactoryGirl.create(:status_message) - StatusMessage.where_person_is_mentioned(@bo).count.should == 2 + expect(StatusMessage.where_person_is_mentioned(@bo).count).to eq(2) end end @@ -39,21 +39,21 @@ describe StatusMessage do describe '.tag_steam' do it 'returns status messages tagged with the tag' do tag_stream = StatusMessage.send(:tag_stream, [@tag_id]) - tag_stream.should include @sm1 - tag_stream.should include @sm2 + expect(tag_stream).to include @sm1 + expect(tag_stream).to include @sm2 end end describe '.public_tag_stream' do it 'returns public status messages tagged with the tag' do - StatusMessage.public_tag_stream([@tag_id]).should == [@sm1] + expect(StatusMessage.public_tag_stream([@tag_id])).to eq([@sm1]) end end describe '.user_tag_stream' do - it 'returns tag stream thats owned or visibile by' do - StatusMessage.should_receive(:owned_or_visible_by_user).with(bob).and_return(StatusMessage) - StatusMessage.should_receive(:tag_stream).with([@tag_id]) + it 'returns tag stream thats owned or visible by' do + expect(StatusMessage).to receive(:owned_or_visible_by_user).with(bob).and_return(StatusMessage) + expect(StatusMessage).to receive(:tag_stream).with([@tag_id]) StatusMessage.user_tag_stream(bob, [@tag_id]) end @@ -66,20 +66,20 @@ describe StatusMessage do sm1 = FactoryGirl.create(:status_message, :author => alice.person) sm2 = FactoryGirl.create(:status_message, :author => bob.person) guids = StatusMessage.guids_for_author(alice.person) - guids.should == [sm1.guid] + expect(guids).to eq([sm1.guid]) end end describe '.before_create' do it 'calls build_tags' do status = FactoryGirl.build(:status_message) - status.should_receive(:build_tags) + expect(status).to receive(:build_tags) status.save end it 'calls filter_mentions' do status = FactoryGirl.build(:status_message) - status.should_receive(:filter_mentions) + expect(status).to receive(:filter_mentions) status.save end end @@ -87,7 +87,7 @@ describe StatusMessage do describe '.after_create' do it 'calls create_mentions' do status = FactoryGirl.build(:status_message, text: "text @{Test; #{alice.diaspora_handle}}") - status.should_receive(:create_mentions).and_call_original + expect(status).to receive(:create_mentions).and_call_original status.save end end @@ -97,33 +97,33 @@ describe StatusMessage do person = FactoryGirl.create(:person) post = FactoryGirl.build(:status_message, :author => @user.person) post.diaspora_handle = person.diaspora_handle - post.author.should == person + expect(post.author).to eq(person) end end context "emptyness" do it "needs either a message or at least one photo" do n = @user.build_post(:status_message, :text => nil) - n.should_not be_valid + expect(n).not_to be_valid n.text = "" - n.should_not be_valid + expect(n).not_to be_valid n.text = "wales" - n.should be_valid + expect(n).to be_valid n.text = nil photo = @user.build_post(:photo, :user_file => uploaded_photo, :to => @aspect.id) photo.save! n.photos << photo - n.should be_valid - n.errors.full_messages.should == [] + expect(n).to be_valid + expect(n.errors.full_messages).to eq([]) end it "doesn't check for content when author is remote (federation...)" do p = FactoryGirl.build(:status_message, text: nil) - p.should be_valid + expect(p).to be_valid end end @@ -131,13 +131,13 @@ describe StatusMessage do message = "Users do things" status = @user.post(:status_message, :text => message, :to => @aspect.id) db_status = StatusMessage.find(status.id) - db_status.text.should == message + expect(db_status.text).to eq(message) end it 'should require status messages not be more than 65535 characters long' do message = 'a' * (65535+1) status_message = FactoryGirl.build(:status_message, :text => message) - status_message.should_not be_valid + expect(status_message).not_to be_valid end describe 'mentions' do @@ -152,10 +152,10 @@ STR describe '#create_mentions' do it 'creates a mention for everyone mentioned in the message' do - Diaspora::Mentionable.should_receive(:people_from_string).and_return(@people) + expect(Diaspora::Mentionable).to receive(:people_from_string).and_return(@people) @sm.mentions.delete_all @sm.create_mentions - @sm.mentions(true).map{|m| m.person}.to_set.should == @people.to_set + expect(@sm.mentions(true).map{|m| m.person}.to_set).to eq(@people.to_set) end it 'does not barf if it gets called twice' do @@ -170,32 +170,32 @@ STR describe '#mentioned_people' do it 'calls create_mentions if there are no mentions in the db' do @sm.mentions.delete_all - @sm.should_receive(:create_mentions) + expect(@sm).to receive(:create_mentions) @sm.mentioned_people end it 'returns the mentioned people' do @sm.mentions.delete_all - @sm.mentioned_people.to_set.should == @people.to_set + expect(@sm.mentioned_people.to_set).to eq(@people.to_set) end it 'does not call create_mentions if there are mentions in the db' do - @sm.should_not_receive(:create_mentions) + expect(@sm).not_to receive(:create_mentions) @sm.mentioned_people end end describe "#mentions?" do it 'returns true if the person was mentioned' do - @sm.mentions?(@people[0]).should be true + expect(@sm.mentions?(@people[0])).to be true end it 'returns false if the person was not mentioned' do - @sm.mentions?(FactoryGirl.build(:person)).should be false + expect(@sm.mentions?(FactoryGirl.build(:person))).to be false end end describe "#notify_person" do it 'notifies the person mentioned' do - Notification.should_receive(:notify).with(alice, anything, anything) + expect(Notification).to receive(:notify).with(alice, anything, anything) @sm.notify_person(alice.person) end end @@ -208,7 +208,7 @@ STR author_usr = msg.author.owner aspect_id = author_usr.aspects.first.id - Diaspora::Mentionable.should_receive(:filter_for_aspects) + expect(Diaspora::Mentionable).to receive(:filter_for_aspects) .with(msg_txt, author_usr, aspect_id) msg.send(:filter_mentions) @@ -216,7 +216,7 @@ STR it "doesn't do anything when public" do msg = FactoryGirl.build(:status_message, public: true) - Diaspora::Mentionable.should_not_receive(:filter_for_aspects) + expect(Diaspora::Mentionable).not_to receive(:filter_for_aspects) msg.send(:filter_mentions) end @@ -226,12 +226,12 @@ STR describe "#nsfw" do it 'returns MatchObject (true) if the post contains #nsfw (however capitalised)' do status = FactoryGirl.build(:status_message, :text => "This message is #nSFw") - status.nsfw.should be_truthy + expect(status.nsfw).to be_truthy end it 'returns nil (false) if the post does not contain #nsfw' do status = FactoryGirl.build(:status_message, :text => "This message is #sFW") - status.nsfw.should be false + expect(status.nsfw).to be false end end @@ -264,15 +264,15 @@ STR it 'serializes the escaped, unprocessed message' do text = "[url](http://example.org)<script> alert('xss should be federated');</script>" @message.text = text - @message.to_xml.to_s.should include Builder::XChar.encode(text) + expect(@message.to_xml.to_s).to include Builder::XChar.encode(text) end it 'serializes the message' do - @xml.should include "<raw_message>I hate WALRUSES!</raw_message>" + expect(@xml).to include "<raw_message>I hate WALRUSES!</raw_message>" end it 'serializes the author address' do - @xml.should include(@user.person.diaspora_handle) + expect(@xml).to include(@user.person.diaspora_handle) end describe '.from_xml' do @@ -280,16 +280,16 @@ STR @marshalled = StatusMessage.from_xml(@xml) end it 'marshals the message' do - @marshalled.text.should == "I hate WALRUSES!" + expect(@marshalled.text).to eq("I hate WALRUSES!") end it 'marshals the guid' do - @marshalled.guid.should == @message.guid + expect(@marshalled.guid).to eq(@message.guid) end it 'marshals the author' do - @marshalled.author.should == @message.author + expect(@marshalled.author).to eq(@message.author) end it 'marshals the diaspora_handle' do - @marshalled.diaspora_handle.should == @message.diaspora_handle + expect(@marshalled.diaspora_handle).to eq(@message.diaspora_handle) end end @@ -301,8 +301,8 @@ STR end it 'serializes the photos' do - @xml.should include "photo" - @xml.should include @message.photos.first.remote_photo_path + expect(@xml).to include "photo" + expect(@xml).to include @message.photos.first.remote_photo_path end describe '.from_xml' do @@ -311,7 +311,7 @@ STR end it 'marshals the photos' do - @marshalled.photos.size.should == 2 + expect(@marshalled.photos.size).to eq(2) end end end @@ -323,9 +323,9 @@ STR end it 'serializes the location' do - @xml.should include "location" - @xml.should include "lat" - @xml.should include "lng" + expect(@xml).to include "location" + expect(@xml).to include "lat" + expect(@xml).to include "lng" end describe ".from_xml" do @@ -334,7 +334,7 @@ STR end it 'marshals the location' do - @marshalled.location.should be_present + expect(@marshalled.location).to be_present end end end @@ -346,9 +346,9 @@ STR end it 'serializes the poll' do - @xml.should include "poll" - @xml.should include "question" - @xml.should include "poll_answer" + expect(@xml).to include "poll" + expect(@xml).to include "question" + expect(@xml).to include "poll_answer" end describe ".from_xml" do @@ -357,11 +357,11 @@ STR end it 'marshals the poll' do - @marshalled.poll.should be_present + expect(@marshalled.poll).to be_present end it 'marshals the poll answers' do - @marshalled.poll.poll_answers.size.should == 2 + expect(@marshalled.poll.poll_answers.size).to eq(2) end end end @@ -384,10 +384,10 @@ STR end it 'sets pending to false on any attached photos' do @status_message.after_dispatch(alice) - @photos.all?{|p| p.reload.pending}.should be false + expect(@photos.all?{|p| p.reload.pending}).to be false end it 'dispatches any attached photos' do - alice.should_receive(:dispatch_post).twice + expect(alice).to receive(:dispatch_post).twice @status_message.after_dispatch(alice) end end @@ -400,15 +400,15 @@ STR it 'should queue a GatherOembedData if it includes a link' do sm = FactoryGirl.build(:status_message, :text => @message_text) - Workers::GatherOEmbedData.should_receive(:perform_async).with(instance_of(Fixnum), instance_of(String)) + expect(Workers::GatherOEmbedData).to receive(:perform_async).with(instance_of(Fixnum), instance_of(String)) sm.save end describe '#contains_oembed_url_in_text?' do it 'returns the oembed urls found in the raw message' do sm = FactoryGirl.build(:status_message, :text => @message_text) - sm.contains_oembed_url_in_text?.should_not be_nil - sm.oembed_url.should == @youtube_url + expect(sm.contains_oembed_url_in_text?).not_to be_nil + expect(sm.oembed_url).to eq(@youtube_url) end end end @@ -423,20 +423,20 @@ STR it 'should queue a GatherOpenGraphData if it includes a link' do sm = FactoryGirl.build(:status_message, :text => @message_text) - Workers::GatherOpenGraphData.should_receive(:perform_async).with(instance_of(Fixnum), instance_of(String)) + expect(Workers::GatherOpenGraphData).to receive(:perform_async).with(instance_of(Fixnum), instance_of(String)) sm.save end describe '#contains_open_graph_url_in_text?' do it 'returns the opengraph urls found in the raw message' do sm = FactoryGirl.build(:status_message, :text => @message_text) - sm.contains_open_graph_url_in_text?.should_not be_nil - sm.open_graph_url.should == @ninegag_url + expect(sm.contains_open_graph_url_in_text?).not_to be_nil + expect(sm.open_graph_url).to eq(@ninegag_url) end it 'returns nil if the link is from trusted oembed provider' do sm = FactoryGirl.build(:status_message, :text => @oemessage_text) - sm.contains_open_graph_url_in_text?.should be_nil - sm.open_graph_url.should be_nil + expect(sm.contains_open_graph_url_in_text?).to be_nil + expect(sm.open_graph_url).to be_nil end end end diff --git a/spec/models/tag_following_spec.rb b/spec/models/tag_following_spec.rb index d3f7463ce9e7592ea3bcd2ef2c67675e58f860c2..af7879215db8c19f4b7bc619978f0b592a9868e7 100644 --- a/spec/models/tag_following_spec.rb +++ b/spec/models/tag_following_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' -describe TagFollowing do +describe TagFollowing, :type => :model do before do @tag = FactoryGirl.build(:tag) TagFollowing.create!(:tag => @tag, :user => alice) end it 'validates uniqueness of tag_following scoped through user' do - TagFollowing.new(:tag => @tag, :user => alice).valid?.should be false + expect(TagFollowing.new(:tag => @tag, :user => alice).valid?).to be false end it 'allows multiple tag followings for different users' do - TagFollowing.new(:tag => @tag, :user => bob).valid?.should be true + expect(TagFollowing.new(:tag => @tag, :user => bob).valid?).to be true end it 'user is following a tag' do - TagFollowing.user_is_following?(alice, @tag.name).should be true + expect(TagFollowing.user_is_following?(alice, @tag.name)).to be true end it 'user not following a tag' do - TagFollowing.user_is_following?(bob, @tag.name).should be false + expect(TagFollowing.user_is_following?(bob, @tag.name)).to be false end end diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index cc8a1ad0061be16a59d90601ddb20a22633a4ae2..1cfad5c140140785a6d9c85c2b51b2554d3e11ef 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe User::Connecting do +describe User::Connecting, :type => :model do let(:aspect) { alice.aspects.first } let(:aspect1) { alice.aspects.create(:name => 'other') } @@ -20,37 +20,37 @@ describe User::Connecting do describe '#remove_contact' do it 'removed non mutual contacts' do alice.share_with(eve.person, alice.aspects.first) - lambda { + expect { alice.remove_contact alice.contact_for(eve.person) - }.should change { + }.to change { alice.contacts(true).count }.by(-1) end it 'removes a contacts receiving flag' do - bob.contacts.find_by_person_id(alice.person.id).should be_receiving + expect(bob.contacts.find_by_person_id(alice.person.id)).to be_receiving bob.remove_contact(bob.contact_for(alice.person)) - bob.contacts(true).find_by_person_id(alice.person.id).should_not be_receiving + expect(bob.contacts(true).find_by_person_id(alice.person.id)).not_to be_receiving end end describe '#disconnected_by' do it 'calls remove contact' do - bob.should_receive(:remove_contact).with(bob.contact_for(alice.person), :retracted => true) + expect(bob).to receive(:remove_contact).with(bob.contact_for(alice.person), :retracted => true) bob.disconnected_by(alice.person) end it 'removes contact sharing flag' do - bob.contacts.find_by_person_id(alice.person.id).should be_sharing + expect(bob.contacts.find_by_person_id(alice.person.id)).to be_sharing bob.disconnected_by(alice.person) - bob.contacts.find_by_person_id(alice.person.id).should_not be_sharing + expect(bob.contacts.find_by_person_id(alice.person.id)).not_to be_sharing end it 'removes notitications' do alice.share_with(eve.person, alice.aspects.first) - Notifications::StartedSharing.where(:recipient_id => eve.id).first.should_not be_nil + expect(Notifications::StartedSharing.where(:recipient_id => eve.id).first).not_to be_nil eve.disconnected_by(alice.person) - Notifications::StartedSharing.where(:recipient_id => eve.id).first.should be_nil + expect(Notifications::StartedSharing.where(:recipient_id => eve.id).first).to be_nil end end @@ -58,14 +58,14 @@ describe User::Connecting do it 'calls remove contact' do contact = bob.contact_for(alice.person) - bob.should_receive(:remove_contact).with(contact, {}) + expect(bob).to receive(:remove_contact).with(contact, {}) bob.disconnect(contact) end it 'dispatches a retraction' do p = double() - Postzord::Dispatcher.should_receive(:build).and_return(p) - p.should_receive(:post) + expect(Postzord::Dispatcher).to receive(:build).and_return(p) + expect(p).to receive(:post) bob.disconnect bob.contact_for(eve.person) end @@ -75,9 +75,9 @@ describe User::Connecting do new_aspect = alice.aspects.create(:name => 'new') alice.add_contact_to_aspect(contact, new_aspect) - lambda { + expect { alice.disconnect(contact) - }.should change(contact.aspects(true), :count).from(2).to(0) + }.to change(contact.aspects(true), :count).from(2).to(0) end end end @@ -94,43 +94,43 @@ describe User::Connecting do describe '#share_with' do it 'finds or creates a contact' do - lambda { + expect { alice.share_with(eve.person, alice.aspects.first) - }.should change(alice.contacts, :count).by(1) + }.to change(alice.contacts, :count).by(1) end it 'does not set mutual on intial share request' do alice.share_with(eve.person, alice.aspects.first) - alice.contacts.find_by_person_id(eve.person.id).should_not be_mutual + expect(alice.contacts.find_by_person_id(eve.person.id)).not_to be_mutual end it 'does set mutual on share-back request' do eve.share_with(alice.person, eve.aspects.first) alice.share_with(eve.person, alice.aspects.first) - alice.contacts.find_by_person_id(eve.person.id).should be_mutual + expect(alice.contacts.find_by_person_id(eve.person.id)).to be_mutual end it 'adds a contact to an aspect' do contact = alice.contacts.create(:person => eve.person) - alice.contacts.stub(:find_or_initialize_by).and_return(contact) + allow(alice.contacts).to receive(:find_or_initialize_by).and_return(contact) - lambda { + expect { alice.share_with(eve.person, alice.aspects.first) - }.should change(contact.aspects, :count).by(1) + }.to change(contact.aspects, :count).by(1) end it 'calls #register_share_visibilities with a contact' do - eve.should_receive(:register_share_visibilities) + expect(eve).to receive(:register_share_visibilities) eve.share_with(alice.person, eve.aspects.first) end context 'dispatching' do it 'dispatches a request on initial request' do contact = alice.contacts.new(:person => eve.person) - alice.contacts.stub(:find_or_initialize_by).and_return(contact) + allow(alice.contacts).to receive(:find_or_initialize_by).and_return(contact) - contact.should_receive(:dispatch_request) + expect(contact).to receive(:dispatch_request) alice.share_with(eve.person, alice.aspects.first) end @@ -138,9 +138,9 @@ describe User::Connecting do eve.share_with(alice.person, eve.aspects.first) contact = alice.contact_for(eve.person) - alice.contacts.stub(:find_or_initialize_by).and_return(contact) + allow(alice.contacts).to receive(:find_or_initialize_by).and_return(contact) - contact.should_receive(:dispatch_request) + expect(contact).to receive(:dispatch_request) alice.share_with(eve.person, alice.aspects.first) end @@ -148,31 +148,31 @@ describe User::Connecting do a2 = alice.aspects.create(:name => "two") contact = alice.contacts.create(:person => eve.person, :receiving => true) - alice.contacts.stub(:find_or_initialize_by).and_return(contact) + allow(alice.contacts).to receive(:find_or_initialize_by).and_return(contact) - contact.should_not_receive(:dispatch_request) + expect(contact).not_to receive(:dispatch_request) alice.share_with(eve.person, a2) end it 'posts profile' do m = double() - Postzord::Dispatcher.should_receive(:build).twice.and_return(m) - m.should_receive(:post).twice + expect(Postzord::Dispatcher).to receive(:build).twice.and_return(m) + expect(m).to receive(:post).twice alice.share_with(eve.person, alice.aspects.first) end end it 'sets receiving' do alice.share_with(eve.person, alice.aspects.first) - alice.contact_for(eve.person).should be_receiving + expect(alice.contact_for(eve.person)).to be_receiving end it "should mark the corresponding notification as 'read'" do notification = FactoryGirl.create(:notification, :target => eve.person) - Notification.where(:target_id => eve.person.id).first.unread.should be true + expect(Notification.where(:target_id => eve.person.id).first.unread).to be true alice.share_with(eve.person, aspect) - Notification.where(:target_id => eve.person.id).first.unread.should be false + expect(Notification.where(:target_id => eve.person.id).first.unread).to be false end end end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 08544e024417841f904adb0da3f156e1c047bcda..5966ba2bf7aa9890a88ab3809c2c1afb8d2f994f 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe User do +describe User, :type => :model do before do @aspect = alice.aspects.first @aspect1 = alice.aspects.create(:name => 'other') @@ -20,48 +20,49 @@ describe User do end it 'saves post into visible post ids' do - lambda { + expect { alice.add_to_streams(@post, @aspects) - }.should change{alice.visible_shareables(Post, :by_members_of => @aspects).length}.by(1) - alice.visible_shareables(Post, :by_members_of => @aspects).should include @post + }.to change{alice.visible_shareables(Post, :by_members_of => @aspects).length}.by(1) + expect(alice.visible_shareables(Post, :by_members_of => @aspects)).to include @post end it 'saves post into each aspect in aspect_ids' do alice.add_to_streams(@post, @aspects) - @aspect.reload.post_ids.should include @post.id - @aspect1.reload.post_ids.should include @post.id + expect(@aspect.reload.post_ids).to include @post.id + expect(@aspect1.reload.post_ids).to include @post.id end end describe '#aspects_from_ids' do it 'returns a list of all valid aspects a alice can post to' do aspect_ids = Aspect.all.map(&:id) - alice.aspects_from_ids(aspect_ids).map{|a| a}.should == - alice.aspects.map{|a| a} #RSpec matchers ftw + expect(alice.aspects_from_ids(aspect_ids).map{|a| a}).to eq( + alice.aspects.map{|a| a} + ) #RSpec matchers ftw end it "lets you post to your own aspects" do - alice.aspects_from_ids([@aspect.id]).should == [@aspect] - alice.aspects_from_ids([@aspect1.id]).should == [@aspect1] + expect(alice.aspects_from_ids([@aspect.id])).to eq([@aspect]) + expect(alice.aspects_from_ids([@aspect1.id])).to eq([@aspect1]) end it 'removes aspects that are not yours' do - alice.aspects_from_ids(eve.aspects.first.id).should == [] + expect(alice.aspects_from_ids(eve.aspects.first.id)).to eq([]) end end describe '#build_post' do it 'sets status_message#text' do post = alice.build_post(:status_message, :text => "hey", :to => @aspect.id) - post.text.should == "hey" + expect(post.text).to eq("hey") end it 'does not save a status_message' do post = alice.build_post(:status_message, :text => "hey", :to => @aspect.id) - post.should_not be_persisted + expect(post).not_to be_persisted end it 'does not save a photo' do post = alice.build_post(:photo, :user_file => uploaded_photo, :to => @aspect.id) - post.should_not be_persisted + expect(post).not_to be_persisted end end @@ -71,7 +72,7 @@ describe User do update_hash = {:text => "New caption"} alice.update_post(photo, update_hash) - photo.text.should match(/New/) + expect(photo.text).to match(/New/) end end end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index ec3bec853e2b1013c0d04b69faac4d80f33c890d..8a3eecee02063ebc7d4b4854cc3ab518d44e6e35 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe User::Querying do +describe User::Querying, :type => :model do before do @alices_aspect = alice.aspects.where(:name => "generic").first @eves_aspect = eve.aspects.where(:name => "generic").first @@ -14,12 +14,12 @@ describe User::Querying do describe "#visible_shareable_ids" do it "contains your public posts" do public_post = alice.post(:status_message, :text => "hi", :to => @alices_aspect.id, :public => true) - alice.visible_shareable_ids(Post).should include(public_post.id) + expect(alice.visible_shareable_ids(Post)).to include(public_post.id) end it "contains your non-public posts" do private_post = alice.post(:status_message, :text => "hi", :to => @alices_aspect.id, :public => false) - alice.visible_shareable_ids(Post).should include(private_post.id) + expect(alice.visible_shareable_ids(Post)).to include(private_post.id) end it "contains public posts from people you're following" do @@ -30,37 +30,37 @@ describe User::Querying do eves_public_post = eve.post(:status_message, :text => "hello", :to => 'all', :public => true) # Alice should see it - alice.visible_shareable_ids(Post).should include(eves_public_post.id) + expect(alice.visible_shareable_ids(Post)).to include(eves_public_post.id) end it "does not contain non-public posts from people who are following you" do eve.share_with(alice.person, @eves_aspect) eves_post = eve.post(:status_message, :text => "hello", :to => @eves_aspect.id) - alice.visible_shareable_ids(Post).should_not include(eves_post.id) + expect(alice.visible_shareable_ids(Post)).not_to include(eves_post.id) end it "does not contain non-public posts from aspects you're not in" do dogs = bob.aspects.create(:name => "dogs") invisible_post = bob.post(:status_message, :text => "foobar", :to => dogs.id) - alice.visible_shareable_ids(Post).should_not include(invisible_post.id) + expect(alice.visible_shareable_ids(Post)).not_to include(invisible_post.id) end it "does not contain pending posts" do pending_post = bob.post(:status_message, :text => "hey", :public => true, :to => @bobs_aspect.id, :pending => true) - pending_post.should be_pending - alice.visible_shareable_ids(Post).should_not include pending_post.id + expect(pending_post).to be_pending + expect(alice.visible_shareable_ids(Post)).not_to include pending_post.id end it "does not contain pending photos" do pending_photo = bob.post(:photo, :pending => true, :user_file=> File.open(photo_fixture_name), :to => @bobs_aspect) - alice.visible_shareable_ids(Photo).should_not include pending_photo.id + expect(alice.visible_shareable_ids(Photo)).not_to include pending_photo.id end it "respects the :type option" do post = bob.post(:status_message, :text => "hey", :public => true, :to => @bobs_aspect.id, :pending => false) reshare = bob.post(:reshare, :pending => false, :root_guid => post.guid, :to => @bobs_aspect) - alice.visible_shareable_ids(Post, :type => "Reshare").should include(reshare.id) - alice.visible_shareable_ids(Post, :type => 'StatusMessage').should_not include(reshare.id) + expect(alice.visible_shareable_ids(Post, :type => "Reshare")).to include(reshare.id) + expect(alice.visible_shareable_ids(Post, :type => 'StatusMessage')).not_to include(reshare.id) end it "does not contain duplicate posts" do @@ -70,8 +70,8 @@ describe User::Querying do bobs_post = bob.post(:status_message, :text => "hai to all my people", :to => [@bobs_aspect.id, bobs_other_aspect.id]) - alice.visible_shareable_ids(Post).length.should == 1 - alice.visible_shareable_ids(Post).should include(bobs_post.id) + expect(alice.visible_shareable_ids(Post).length).to eq(1) + expect(alice.visible_shareable_ids(Post)).to include(bobs_post.id) end describe 'hidden posts' do @@ -81,13 +81,13 @@ describe User::Querying do end it "pulls back non hidden posts" do - alice.visible_shareable_ids(Post).include?(@status.id).should be true + expect(alice.visible_shareable_ids(Post).include?(@status.id)).to be true end it "does not pull back hidden posts" do visibility = @status.share_visibilities(Post).where(:contact_id => alice.contact_for(bob.person).id).first visibility.update_attributes(:hidden => true) - alice.visible_shareable_ids(Post).include?(@status.id).should be false + expect(alice.visible_shareable_ids(Post).include?(@status.id)).to be false end end end @@ -95,8 +95,8 @@ describe User::Querying do describe "#prep_opts" do it "defaults the opts" do time = Time.now - Time.stub(:now).and_return(time) - alice.send(:prep_opts, Post, {}).should == { + allow(Time).to receive(:now).and_return(time) + expect(alice.send(:prep_opts, Post, {})).to eq({ :type => Stream::Base::TYPES_OF_POST_IN_STREAM, :order => 'created_at DESC', :limit => 15, @@ -104,14 +104,14 @@ describe User::Querying do :order_field => :created_at, :order_with_table => "posts.created_at DESC", :max_time => time + 1 - } + }) end end describe "#visible_shareables" do it 'never contains posts from people not in your aspects' do FactoryGirl.create(:status_message, :public => true) - bob.visible_shareables(Post).count(:all).should == 0 + expect(bob.visible_shareables(Post).count(:all)).to eq(0) end context 'with two posts with the same timestamp' do @@ -124,8 +124,8 @@ describe User::Querying do end it "returns them in reverse creation order" do - bob.visible_shareables(Post).first.text.should == "second" - bob.visible_shareables(Post).last.text.should == "first" + expect(bob.visible_shareables(Post).first.text).to eq("second") + expect(bob.visible_shareables(Post).last.text).to eq("first") end end @@ -146,40 +146,40 @@ describe User::Querying do end it 'works' do # The set up takes a looong time, so to save time we do several tests in one - bob.visible_shareables(Post).length.should == 15 #it returns 15 by default - bob.visible_shareables(Post).map(&:id).should == bob.visible_shareables(Post, :by_members_of => bob.aspects.map { |a| a.id }).map(&:id) # it is the same when joining through aspects + expect(bob.visible_shareables(Post).length).to eq(15) #it returns 15 by default + expect(bob.visible_shareables(Post).map(&:id)).to eq(bob.visible_shareables(Post, :by_members_of => bob.aspects.map { |a| a.id }).map(&:id)) # it is the same when joining through aspects # checks the default sort order - bob.visible_shareables(Post).sort_by { |p| p.created_at }.map { |p| p.id }.should == bob.visible_shareables(Post).map { |p| p.id }.reverse #it is sorted updated_at desc by default + expect(bob.visible_shareables(Post).sort_by { |p| p.created_at }.map { |p| p.id }).to eq(bob.visible_shareables(Post).map { |p| p.id }.reverse) #it is sorted updated_at desc by default # It should respect the order option opts = {:order => 'created_at DESC'} - bob.visible_shareables(Post, opts).first.created_at.should > bob.visible_shareables(Post, opts).last.created_at + expect(bob.visible_shareables(Post, opts).first.created_at).to be > bob.visible_shareables(Post, opts).last.created_at # It should respect the order option opts = {:order => 'updated_at DESC'} - bob.visible_shareables(Post, opts).first.updated_at.should > bob.visible_shareables(Post, opts).last.updated_at + expect(bob.visible_shareables(Post, opts).first.updated_at).to be > bob.visible_shareables(Post, opts).last.updated_at # It should respect the limit option opts = {:limit => 40} - bob.visible_shareables(Post, opts).length.should == 40 - bob.visible_shareables(Post, opts).map(&:id).should == bob.visible_shareables(Post, opts.merge(:by_members_of => bob.aspects.map { |a| a.id })).map(&:id) - bob.visible_shareables(Post, opts).sort_by { |p| p.created_at }.map { |p| p.id }.should == bob.visible_shareables(Post, opts).map { |p| p.id }.reverse + expect(bob.visible_shareables(Post, opts).length).to eq(40) + expect(bob.visible_shareables(Post, opts).map(&:id)).to eq(bob.visible_shareables(Post, opts.merge(:by_members_of => bob.aspects.map { |a| a.id })).map(&:id)) + expect(bob.visible_shareables(Post, opts).sort_by { |p| p.created_at }.map { |p| p.id }).to eq(bob.visible_shareables(Post, opts).map { |p| p.id }.reverse) # It should paginate using a datetime timestamp last_time_of_last_page = bob.visible_shareables(Post).last.created_at opts = {:max_time => last_time_of_last_page} - bob.visible_shareables(Post, opts).length.should == 15 - bob.visible_shareables(Post, opts).map { |p| p.id }.should == bob.visible_shareables(Post, opts.merge(:by_members_of => bob.aspects.map { |a| a.id })).map { |p| p.id } - bob.visible_shareables(Post, opts).sort_by { |p| p.created_at}.map { |p| p.id }.should == bob.visible_shareables(Post, opts).map { |p| p.id }.reverse - bob.visible_shareables(Post, opts).map { |p| p.id }.should == bob.visible_shareables(Post, :limit => 40)[15...30].map { |p| p.id } #pagination should return the right posts + expect(bob.visible_shareables(Post, opts).length).to eq(15) + expect(bob.visible_shareables(Post, opts).map { |p| p.id }).to eq(bob.visible_shareables(Post, opts.merge(:by_members_of => bob.aspects.map { |a| a.id })).map { |p| p.id }) + expect(bob.visible_shareables(Post, opts).sort_by { |p| p.created_at}.map { |p| p.id }).to eq(bob.visible_shareables(Post, opts).map { |p| p.id }.reverse) + expect(bob.visible_shareables(Post, opts).map { |p| p.id }).to eq(bob.visible_shareables(Post, :limit => 40)[15...30].map { |p| p.id }) #pagination should return the right posts # It should paginate using an integer timestamp opts = {:max_time => last_time_of_last_page.to_i} - bob.visible_shareables(Post, opts).length.should == 15 - bob.visible_shareables(Post, opts).map { |p| p.id }.should == bob.visible_shareables(Post, opts.merge(:by_members_of => bob.aspects.map { |a| a.id })).map { |p| p.id } - bob.visible_shareables(Post, opts).sort_by { |p| p.created_at}.map { |p| p.id }.should == bob.visible_shareables(Post, opts).map { |p| p.id }.reverse - bob.visible_shareables(Post, opts).map { |p| p.id }.should == bob.visible_shareables(Post, :limit => 40)[15...30].map { |p| p.id } #pagination should return the right posts + expect(bob.visible_shareables(Post, opts).length).to eq(15) + expect(bob.visible_shareables(Post, opts).map { |p| p.id }).to eq(bob.visible_shareables(Post, opts.merge(:by_members_of => bob.aspects.map { |a| a.id })).map { |p| p.id }) + expect(bob.visible_shareables(Post, opts).sort_by { |p| p.created_at}.map { |p| p.id }).to eq(bob.visible_shareables(Post, opts).map { |p| p.id }.reverse) + expect(bob.visible_shareables(Post, opts).map { |p| p.id }).to eq(bob.visible_shareables(Post, :limit => 40)[15...30].map { |p| p.id }) #pagination should return the right posts end end end @@ -187,19 +187,19 @@ describe User::Querying do describe '#find_visible_shareable_by_id' do it "returns a post if you can see it" do bobs_post = bob.post(:status_message, :text => "hi", :to => @bobs_aspect.id, :public => false) - alice.find_visible_shareable_by_id(Post, bobs_post.id).should == bobs_post + expect(alice.find_visible_shareable_by_id(Post, bobs_post.id)).to eq(bobs_post) end it "returns nil if you can't see that post" do dogs = bob.aspects.create(:name => "dogs") invisible_post = bob.post(:status_message, :text => "foobar", :to => dogs.id) - alice.find_visible_shareable_by_id(Post, invisible_post.id).should be_nil + expect(alice.find_visible_shareable_by_id(Post, invisible_post.id)).to be_nil end end context 'with two users' do describe '#people_in_aspects' do it 'returns people objects for a users contact in each aspect' do - alice.people_in_aspects([@alices_aspect]).should == [bob.person] + expect(alice.people_in_aspects([@alices_aspect])).to eq([bob.person]) end it 'returns local/remote people objects for a users contact in each aspect' do @@ -220,22 +220,22 @@ describe User::Querying do local_person.save local_person.reload - alice.people_in_aspects([@alices_aspect]).count.should == 4 - alice.people_in_aspects([@alices_aspect], :type => 'remote').count.should == 1 - alice.people_in_aspects([@alices_aspect], :type => 'local').count.should == 3 + expect(alice.people_in_aspects([@alices_aspect]).count).to eq(4) + expect(alice.people_in_aspects([@alices_aspect], :type => 'remote').count).to eq(1) + expect(alice.people_in_aspects([@alices_aspect], :type => 'local').count).to eq(3) end it 'does not return people not connected to user on same pod' do 3.times { FactoryGirl.create(:user) } - alice.people_in_aspects([@alices_aspect]).count.should == 1 + expect(alice.people_in_aspects([@alices_aspect]).count).to eq(1) end it "only returns non-pending contacts" do - alice.people_in_aspects([@alices_aspect]).should == [bob.person] + expect(alice.people_in_aspects([@alices_aspect])).to eq([bob.person]) end it "returns an empty array when passed an aspect the user doesn't own" do - alice.people_in_aspects([@eves_aspect]).should == [] + expect(alice.people_in_aspects([@eves_aspect])).to eq([]) end end end @@ -250,7 +250,7 @@ describe User::Querying do it 'returns a contact' do contact = Contact.create(:user => alice, :person => person_one, :aspects => [aspect]) alice.contacts << contact - alice.contact_for_person_id(person_one.id).should be_truthy + expect(alice.contact_for_person_id(person_one.id)).to be_truthy end it 'returns the correct contact' do @@ -263,28 +263,28 @@ describe User::Querying do contact3 = Contact.create(:user => alice, :person => person_three, :aspects => [aspect]) alice.contacts << contact3 - alice.contact_for_person_id(person_two.id).person.should == person_two + expect(alice.contact_for_person_id(person_two.id).person).to eq(person_two) end it 'returns nil for a non-contact' do - alice.contact_for_person_id(person_one.id).should be_nil + expect(alice.contact_for_person_id(person_one.id)).to be_nil end it 'returns nil when someone else has contact with the target' do contact = Contact.create(:user => alice, :person => person_one, :aspects => [aspect]) alice.contacts << contact - eve.contact_for_person_id(person_one.id).should be_nil + expect(eve.contact_for_person_id(person_one.id)).to be_nil end end describe '#contact_for' do it 'takes a person_id and returns a contact' do - alice.should_receive(:contact_for_person_id).with(person_one.id) + expect(alice).to receive(:contact_for_person_id).with(person_one.id) alice.contact_for(person_one) end it 'returns nil if the input is nil' do - alice.contact_for(nil).should be_nil + expect(alice.contact_for(nil)).to be_nil end end @@ -294,7 +294,7 @@ describe User::Querying do end it 'should return the aspects with given contact' do - alice.aspects_with_person(@connected_person).should == [@alices_aspect] + expect(alice.aspects_with_person(@connected_person)).to eq([@alices_aspect]) end it 'returns multiple aspects if the person is there' do @@ -302,7 +302,7 @@ describe User::Querying do contact = alice.contact_for(@connected_person) alice.add_contact_to_aspect(contact, aspect2) - alice.aspects_with_person(@connected_person).to_set.should == alice.aspects.to_set + expect(alice.aspects_with_person(@connected_person).to_set).to eq(alice.aspects.to_set) end end end @@ -317,11 +317,11 @@ describe User::Querying do end it 'displays public posts for a non-contact' do - alice.posts_from(@user3.person).should include @public_message + expect(alice.posts_from(@user3.person)).to include @public_message end it 'does not display private posts for a non-contact' do - alice.posts_from(@user3.person).should_not include @private_message + expect(alice.posts_from(@user3.person)).not_to include @private_message end it 'displays private and public posts for a non-contact after connecting' do @@ -330,8 +330,8 @@ describe User::Querying do alice.reload - alice.posts_from(@user3.person).should include @public_message - alice.posts_from(@user3.person).should include new_message + expect(alice.posts_from(@user3.person)).to include @public_message + expect(alice.posts_from(@user3.person)).to include new_message end it 'displays recent posts first' do @@ -342,7 +342,7 @@ describe User::Querying do msg4.created_at = Time.now+14 msg4.save! - alice.posts_from(@user3.person).map { |p| p.id }.should == [msg4, msg3, @public_message].map { |p| p.id } + expect(alice.posts_from(@user3.person).map { |p| p.id }).to eq([msg4, msg3, @public_message].map { |p| p.id }) end end end diff --git a/spec/models/user/social_actions_spec.rb b/spec/models/user/social_actions_spec.rb index de486010d781d4c19718b473ed6b1fc8bec7f582..74a67608be1a8b931ba89469ec365a37d63b5eaa 100644 --- a/spec/models/user/social_actions_spec.rb +++ b/spec/models/user/social_actions_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe User::SocialActions do +describe User::SocialActions, :type => :model do before do @bobs_aspect = bob.aspects.where(:name => "generic").first @status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id) @@ -8,39 +8,39 @@ describe User::SocialActions do describe 'User#comment!' do it "sets the comment text" do - alice.comment!(@status, "unicorn_mountain").text.should == "unicorn_mountain" + expect(alice.comment!(@status, "unicorn_mountain").text).to eq("unicorn_mountain") end it "creates a partcipation" do - lambda{ alice.comment!(@status, "bro") }.should change(Participation, :count).by(1) - alice.participations.last.target.should == @status + expect{ alice.comment!(@status, "bro") }.to change(Participation, :count).by(1) + expect(alice.participations.last.target).to eq(@status) end it "creates the comment" do - lambda{ alice.comment!(@status, "bro") }.should change(Comment, :count).by(1) + expect{ alice.comment!(@status, "bro") }.to change(Comment, :count).by(1) end it "federates" do - Participation::Generator.any_instance.stub(:create!) - Postzord::Dispatcher.should_receive(:defer_build_and_post) + allow_any_instance_of(Participation::Generator).to receive(:create!) + expect(Postzord::Dispatcher).to receive(:defer_build_and_post) alice.comment!(@status, "omg") end end describe 'User#like!' do it "creates a partcipation" do - lambda{ alice.like!(@status) }.should change(Participation, :count).by(1) - alice.participations.last.target.should == @status + expect{ alice.like!(@status) }.to change(Participation, :count).by(1) + expect(alice.participations.last.target).to eq(@status) end it "creates the like" do - lambda{ alice.like!(@status) }.should change(Like, :count).by(1) + expect{ alice.like!(@status) }.to change(Like, :count).by(1) end it "federates" do #participation and like - Participation::Generator.any_instance.stub(:create!) - Postzord::Dispatcher.should_receive(:defer_build_and_post) + allow_any_instance_of(Participation::Generator).to receive(:create!) + expect(Postzord::Dispatcher).to receive(:defer_build_and_post) alice.like!(@status) end end @@ -52,27 +52,27 @@ describe User::SocialActions do end it "creates a partcipation" do - lambda{ alice.like!(@status) }.should change(Participation, :count).by(1) + expect{ alice.like!(@status) }.to change(Participation, :count).by(1) end it "creates the like" do - lambda{ alice.like!(@status) }.should change(Like, :count).by(1) + expect{ alice.like!(@status) }.to change(Like, :count).by(1) end it "federates" do #participation and like - Postzord::Dispatcher.should_receive(:defer_build_and_post).twice + expect(Postzord::Dispatcher).to receive(:defer_build_and_post).twice alice.like!(@status) end it "should be able to like on one's own status" do like = alice.like!(@status) - @status.reload.likes.first.should == like + expect(@status.reload.likes.first).to eq(like) end it "should be able to like on a contact's status" do like = bob.like!(@status) - @status.reload.likes.first.should == like + expect(@status.reload.likes.first).to eq(like) end it "does not allow multiple likes" do @@ -80,7 +80,7 @@ describe User::SocialActions do likes = @status.likes expect { alice.like!(@status) }.to raise_error - @status.reload.likes.should == likes + expect(@status.reload.likes).to eq(likes) end end @@ -93,21 +93,21 @@ describe User::SocialActions do end it "federates" do - Participation::Generator.any_instance.stub(:create!) - Postzord::Dispatcher.should_receive(:defer_build_and_post) + allow_any_instance_of(Participation::Generator).to receive(:create!) + expect(Postzord::Dispatcher).to receive(:defer_build_and_post) alice.participate_in_poll!(@status, @answer) end it "creates a partcipation" do - lambda{ alice.participate_in_poll!(@status, @answer) }.should change(Participation, :count).by(1) + expect{ alice.participate_in_poll!(@status, @answer) }.to change(Participation, :count).by(1) end it "creates the poll participation" do - lambda{ alice.participate_in_poll!(@status, @answer) }.should change(PollParticipation, :count).by(1) + expect{ alice.participate_in_poll!(@status, @answer) }.to change(PollParticipation, :count).by(1) end it "sets the poll answer id" do - alice.participate_in_poll!(@status, @answer).poll_answer.should == @answer + expect(alice.participate_in_poll!(@status, @answer).poll_answer).to eq(@answer) end end end \ No newline at end of file diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb index 25bbe15d2b4d2c71e8c297d23d9ff1889e2a214d..022b54db853c9714a45c4b5d4e7401b3397f55d1 100644 --- a/spec/models/user_preference_spec.rb +++ b/spec/models/user_preference_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe UserPreference do +describe UserPreference, :type => :model do it 'should only allow valid email types to exist' do pref = alice.user_preferences.new(:email_type => 'not_valid') - pref.should_not be_valid + expect(pref).not_to be_valid end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 07ed9d9054f21e167f6b15eba8a6e5cde7b86297..1f52e78b7ac18d3e644456733a2e74f61b5e78ce 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -4,18 +4,18 @@ require 'spec_helper' -describe User do +describe User, :type => :model do context "relations" do context "#conversations" do it "doesn't find anything when there is nothing to find" do u = FactoryGirl.create(:user) - u.conversations.should be_empty + expect(u.conversations).to be_empty end it "finds the users conversations" do c = FactoryGirl.create(:conversation, { author: alice.person }) - alice.conversations.should include c + expect(alice.conversations).to include c end it "doesn't find other users conversations" do @@ -23,23 +23,23 @@ describe User do c2 = FactoryGirl.create(:conversation) c_own = FactoryGirl.create(:conversation, { author: alice.person }) - alice.conversations.should include c_own - alice.conversations.should_not include c1 - alice.conversations.should_not include c2 + expect(alice.conversations).to include c_own + expect(alice.conversations).not_to include c1 + expect(alice.conversations).not_to include c2 end end end describe "private key" do it 'has a key' do - alice.encryption_key.should_not be nil + expect(alice.encryption_key).not_to be nil end it 'marshalls the key to and from the db correctly' do user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password') user.save! - user.serialized_private_key.should be_present + expect(user.serialized_private_key).to be_present expect{ user.reload.encryption_key @@ -52,14 +52,14 @@ describe User do user = FactoryGirl.build(:user) user.last_seen = Time.now - 1.month user.save - User.yearly_actives.should include user + expect(User.yearly_actives).to include user end it 'returns list which does not include users seen within last year' do user = FactoryGirl.build(:user) user.last_seen = Time.now - 2.year user.save - User.yearly_actives.should_not include user + expect(User.yearly_actives).not_to include user end end @@ -68,14 +68,14 @@ describe User do user = FactoryGirl.build(:user) user.last_seen = Time.now - 1.day user.save - User.monthly_actives.should include user + expect(User.monthly_actives).to include user end it 'returns list which does not include users seen within last month' do user = FactoryGirl.build(:user) user.last_seen = Time.now - 2.month user.save - User.monthly_actives.should_not include user + expect(User.monthly_actives).not_to include user end end @@ -84,14 +84,14 @@ describe User do user = FactoryGirl.build(:user) user.last_seen = Time.now - 1.hour user.save - User.daily_actives.should include(user) + expect(User.daily_actives).to include(user) end it 'returns list which does not include users seen within last day' do user = FactoryGirl.build(:user) user.last_seen = Time.now - 2.day user.save - User.daily_actives.should_not include(user) + expect(User.daily_actives).not_to include(user) end end @@ -100,14 +100,14 @@ describe User do user = FactoryGirl.build(:user) user.last_seen = Time.now - 4.month user.save - User.halfyear_actives.should include user + expect(User.halfyear_actives).to include user end it 'returns list which does not include users seen within the last half a year' do user = FactoryGirl.build(:user) user.last_seen = Time.now - 7.month user.save - User.halfyear_actives.should_not include user + expect(User.halfyear_actives).not_to include user end end @@ -115,12 +115,12 @@ describe User do describe '#save_person!' do it 'saves the corresponding user if it has changed' do alice.person.url = "http://stuff.com" - Person.any_instance.should_receive(:save) + expect_any_instance_of(Person).to receive(:save) alice.save end it 'does not save the corresponding user if it has not changed' do - Person.any_instance.should_not_receive(:save) + expect_any_instance_of(Person).not_to receive(:save) alice.save end end @@ -134,13 +134,13 @@ describe User do end it 'is a hash' do - alice.hidden_shareables.should == {} + expect(alice.hidden_shareables).to eq({}) end describe '#add_hidden_shareable' do it 'adds the share id to an array which is keyed by the objects class' do alice.add_hidden_shareable(@sm_class, @sm_id) - alice.hidden_shareables['Post'].should == [@sm_id] + expect(alice.hidden_shareables['Post']).to eq([@sm_id]) end it 'handles having multiple posts' do @@ -148,7 +148,7 @@ describe User do alice.add_hidden_shareable(@sm_class, @sm_id) alice.add_hidden_shareable(sm2.class.base_class.to_s, sm2.id.to_s) - alice.hidden_shareables['Post'].should =~ [@sm_id, sm2.id.to_s] + expect(alice.hidden_shareables['Post']).to match_array([@sm_id, sm2.id.to_s]) end it 'handles having multiple shareable types' do @@ -156,7 +156,7 @@ describe User do alice.add_hidden_shareable(photo.class.base_class.to_s, photo.id.to_s) alice.add_hidden_shareable(@sm_class, @sm_id) - alice.hidden_shareables['Photo'].should == [photo.id.to_s] + expect(alice.hidden_shareables['Photo']).to eq([photo.id.to_s]) end end @@ -164,20 +164,20 @@ describe User do it 'removes the id from the hash if it is there' do alice.add_hidden_shareable(@sm_class, @sm_id) alice.remove_hidden_shareable(@sm_class, @sm_id) - alice.hidden_shareables['Post'].should == [] + expect(alice.hidden_shareables['Post']).to eq([]) end end describe 'toggle_hidden_shareable' do it 'calls add_hidden_shareable if the key does not exist, and returns true' do - alice.should_receive(:add_hidden_shareable).with(@sm_class, @sm_id) - alice.toggle_hidden_shareable(@sm).should be true + expect(alice).to receive(:add_hidden_shareable).with(@sm_class, @sm_id) + expect(alice.toggle_hidden_shareable(@sm)).to be true end it 'calls remove_hidden_shareable if the key exists' do - alice.should_receive(:remove_hidden_shareable).with(@sm_class, @sm_id) + expect(alice).to receive(:remove_hidden_shareable).with(@sm_class, @sm_id) alice.add_hidden_shareable(@sm_class, @sm_id) - alice.toggle_hidden_shareable(@sm).should be false + expect(alice.toggle_hidden_shareable(@sm)).to be false end end @@ -185,12 +185,12 @@ describe User do it 'returns true if the shareable is hidden' do post = FactoryGirl.create(:status_message) bob.toggle_hidden_shareable(post) - bob.is_shareable_hidden?(post).should be true + expect(bob.is_shareable_hidden?(post)).to be true end it 'returns false if the shareable is not present' do post = FactoryGirl.create(:status_message) - bob.is_shareable_hidden?(post).should be false + expect(bob.is_shareable_hidden?(post)).to be false end end end @@ -198,9 +198,9 @@ describe User do describe 'overwriting people' do it 'does not overwrite old users with factory' do - lambda { + expect { new_user = FactoryGirl.create(:user, :id => alice.id) - }.should raise_error ActiveRecord::StatementInvalid + }.to raise_error ActiveRecord::StatementInvalid end it 'does not overwrite old users with create' do @@ -217,8 +217,8 @@ describe User do params[:id] = alice.id new_user = User.build(params) new_user.save - new_user.persisted?.should be true - new_user.id.should_not == alice.id + expect(new_user.persisted?).to be true + expect(new_user.id).not_to eq(alice.id) end end @@ -226,81 +226,81 @@ describe User do describe "of associated person" do it "fails if person is not valid" do user = alice - user.should be_valid + expect(user).to be_valid user.person.serialized_public_key = nil - user.person.should_not be_valid - user.should_not be_valid + expect(user.person).not_to be_valid + expect(user).not_to be_valid - user.errors.full_messages.count.should == 1 - user.errors.full_messages.first.should =~ /Person is invalid/i + expect(user.errors.full_messages.count).to eq(1) + expect(user.errors.full_messages.first).to match(/Person is invalid/i) end end describe "of username" do it "requires presence" do alice.username = nil - alice.should_not be_valid + expect(alice).not_to be_valid end it "requires uniqueness" do alice.username = eve.username - alice.should_not be_valid + expect(alice).not_to be_valid end it 'requires uniqueness also amount Person objects with diaspora handle' do p = FactoryGirl.create(:person, :diaspora_handle => "jimmy#{User.diaspora_id_host}") alice.username = 'jimmy' - alice.should_not be_valid + expect(alice).not_to be_valid end it "downcases username" do user = FactoryGirl.build(:user, :username => "WeIrDcAsE") - user.should be_valid - user.username.should == "weirdcase" + expect(user).to be_valid + expect(user.username).to eq("weirdcase") end it "fails if the requested username is only different in case from an existing username" do alice.username = eve.username.upcase - alice.should_not be_valid + expect(alice).not_to be_valid end it "strips leading and trailing whitespace" do user = FactoryGirl.build(:user, :username => " janie ") - user.should be_valid - user.username.should == "janie" + expect(user).to be_valid + expect(user.username).to eq("janie") end it "fails if there's whitespace in the middle" do alice.username = "bobby tables" - alice.should_not be_valid + expect(alice).not_to be_valid end it 'can not contain non url safe characters' do alice.username = "kittens;" - alice.should_not be_valid + expect(alice).not_to be_valid end it 'should not contain periods' do alice.username = "kittens." - alice.should_not be_valid + expect(alice).not_to be_valid end it "can be 32 characters long" do alice.username = "hexagoooooooooooooooooooooooooon" - alice.should be_valid + expect(alice).to be_valid end it "cannot be 33 characters" do alice.username = "hexagooooooooooooooooooooooooooon" - alice.should_not be_valid + expect(alice).not_to be_valid end it "cannot be one of the blacklist names" do ['hostmaster', 'postmaster', 'root', 'webmaster'].each do |username| alice.username = username - alice.should_not be_valid + expect(alice).not_to be_valid end end end @@ -308,37 +308,37 @@ describe User do describe "of email" do it "requires email address" do alice.email = nil - alice.should_not be_valid + expect(alice).not_to be_valid end it "requires a unique email address" do alice.email = eve.email - alice.should_not be_valid + expect(alice).not_to be_valid end it "requires a valid email address" do alice.email = "somebody@anywhere" - alice.should_not be_valid + expect(alice).not_to be_valid end end describe "of unconfirmed_email" do it "unconfirmed_email address can be nil/blank" do alice.unconfirmed_email = nil - alice.should be_valid + expect(alice).to be_valid alice.unconfirmed_email = "" - alice.should be_valid + expect(alice).to be_valid end it "does NOT require a unique unconfirmed_email address" do eve.update_attribute :unconfirmed_email, "new@email.com" alice.unconfirmed_email = "new@email.com" - alice.should be_valid + expect(alice).to be_valid end it "requires a valid unconfirmed_email address" do alice.unconfirmed_email = "somebody@anywhere" - alice.should_not be_valid + expect(alice).not_to be_valid end end @@ -349,19 +349,19 @@ describe User do it "requires availability" do alice.language = 'some invalid language' - alice.should_not be_valid + expect(alice).not_to be_valid end it "should save with current language if blank" do I18n.locale = :fr user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password') - user.language.should == 'fr' + expect(user.language).to eq('fr') end it "should save with language what is set" do I18n.locale = :fr user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password', :language => 'de') - user.language.should == 'de' + expect(user.language).to eq('de') end end end @@ -384,17 +384,17 @@ describe User do end it "does not save" do - @user.persisted?.should be false - @user.person.persisted?.should be false - User.find_by_username("ohai").should be_nil + expect(@user.persisted?).to be false + expect(@user.person.persisted?).to be false + expect(User.find_by_username("ohai")).to be_nil end it 'saves successfully' do - @user.should be_valid - @user.save.should be true - @user.persisted?.should be true - @user.person.persisted?.should be true - User.find_by_username("ohai").should == @user + expect(@user).to be_valid + expect(@user.save).to be true + expect(@user.persisted?).to be true + expect(@user.person.persisted?).to be true + expect(User.find_by_username("ohai")).to eq(@user) end end @@ -409,19 +409,19 @@ describe User do end it "raises no error" do - lambda { User.build(@invalid_params) }.should_not raise_error + expect { User.build(@invalid_params) }.not_to raise_error end it "does not save" do - User.build(@invalid_params).save.should be false + expect(User.build(@invalid_params).save).to be false end it 'does not save a person' do - lambda { User.build(@invalid_params) }.should_not change(Person, :count) + expect { User.build(@invalid_params) }.not_to change(Person, :count) end it 'does not generate a key' do - User.should_receive(:generate_key).exactly(0).times + expect(User).to receive(:generate_key).exactly(0).times User.build(@invalid_params) end end @@ -443,7 +443,7 @@ describe User do end it "does not assign it to the person" do - User.build(@invalid_params).person.id.should_not == person.id + expect(User.build(@invalid_params).person.id).not_to eq(person.id) end end end @@ -453,7 +453,7 @@ describe User do inv = InvitationCode.create(:user => bob) user = FactoryGirl.build(:user) user.process_invite_acceptence(inv) - user.invited_by_id.should == bob.id + expect(user.invited_by_id).to eq(bob.id) end end @@ -474,27 +474,27 @@ describe User do expect { alice.update_user_preferences({'mentioned' => false}) }.to change(alice.user_preferences, :count).by(@pref_count-1) - alice.reload.disable_mail.should be false + expect(alice.reload.disable_mail).to be false end end describe ".find_for_database_authentication" do it 'finds a user' do - User.find_for_database_authentication(:username => alice.username).should == alice + expect(User.find_for_database_authentication(:username => alice.username)).to eq(alice) end it 'finds a user by email' do - User.find_for_database_authentication(:username => alice.email).should == alice + expect(User.find_for_database_authentication(:username => alice.email)).to eq(alice) end it "does not preserve case" do - User.find_for_database_authentication(:username => alice.username.upcase).should == alice + expect(User.find_for_database_authentication(:username => alice.username.upcase)).to eq(alice) end it 'errors out when passed a non-hash' do - lambda { + expect { User.find_for_database_authentication(alice.username) - }.should raise_error + }.to raise_error end end @@ -509,26 +509,26 @@ describe User do it 'dispatches the profile when tags are set' do @params = {:tag_string => '#what #hey'} mailman = Postzord::Dispatcher.build(alice, Profile.new) - Postzord::Dispatcher.should_receive(:build).and_return(mailman) - alice.update_profile(@params).should be true + expect(Postzord::Dispatcher).to receive(:build).and_return(mailman) + expect(alice.update_profile(@params)).to be true end it 'sends a profile to their contacts' do mailman = Postzord::Dispatcher.build(alice, Profile.new) - Postzord::Dispatcher.should_receive(:build).and_return(mailman) - alice.update_profile(@params).should be true + expect(Postzord::Dispatcher).to receive(:build).and_return(mailman) + expect(alice.update_profile(@params)).to be true end it 'updates names' do - alice.update_profile(@params).should be true - alice.reload.profile.first_name.should == 'bob' + expect(alice.update_profile(@params)).to be true + expect(alice.reload.profile.first_name).to eq('bob') end it 'updates image_url' do params = {:image_url => "http://clown.com"} - alice.update_profile(params).should be true - alice.reload.profile.image_url.should == "http://clown.com" + expect(alice.update_profile(params)).to be true + expect(alice.reload.profile.image_url).to eq("http://clown.com") end context 'passing in a photo' do @@ -542,20 +542,20 @@ describe User do end it 'updates image_url' do - alice.update_profile(@params).should be true + expect(alice.update_profile(@params)).to be true alice.reload - alice.profile.image_url.should =~ Regexp.new(@photo.url(:thumb_large)) - alice.profile.image_url_medium.should =~ Regexp.new(@photo.url(:thumb_medium)) - alice.profile.image_url_small.should =~ Regexp.new(@photo.url(:thumb_small)) + expect(alice.profile.image_url).to match(Regexp.new(@photo.url(:thumb_large))) + expect(alice.profile.image_url_medium).to match(Regexp.new(@photo.url(:thumb_medium))) + expect(alice.profile.image_url_small).to match(Regexp.new(@photo.url(:thumb_small))) end it 'unpends the photo' do @photo.pending = true @photo.save! @photo.reload - alice.update_profile(@params).should be true - @photo.reload.pending.should be false + expect(alice.update_profile(@params)).to be true + expect(@photo.reload.pending).to be false end end end @@ -563,7 +563,7 @@ describe User do describe '#update_post' do it 'should dispatch post' do photo = alice.build_post(:photo, :user_file => uploaded_photo, :text => "hello", :to => alice.aspects.first.id) - alice.should_receive(:dispatch_post).with(photo) + expect(alice).to receive(:dispatch_post).with(photo) alice.update_post(photo, :text => 'hellp') end end @@ -574,23 +574,23 @@ describe User do end it 'notifies the user if the incoming post mentions them' do - @post.should_receive(:mentions?).with(alice.person).and_return(true) - @post.should_receive(:notify_person).with(alice.person) + expect(@post).to receive(:mentions?).with(alice.person).and_return(true) + expect(@post).to receive(:notify_person).with(alice.person) alice.notify_if_mentioned(@post) end it 'does not notify the user if the incoming post does not mention them' do - @post.should_receive(:mentions?).with(alice.person).and_return(false) - @post.should_not_receive(:notify_person) + expect(@post).to receive(:mentions?).with(alice.person).and_return(false) + expect(@post).not_to receive(:notify_person) alice.notify_if_mentioned(@post) end it 'does not notify the user if the post author is not a contact' do @post = FactoryGirl.build(:status_message, :author => eve.person) - @post.stub(:mentions?).and_return(true) - @post.should_not_receive(:notify_person) + allow(@post).to receive(:mentions?).and_return(true) + expect(@post).not_to receive(:notify_person) alice.notify_if_mentioned(@post) end @@ -600,23 +600,23 @@ describe User do describe '#destroy' do it 'removes invitations from the user' do FactoryGirl.create(:invitation, :sender => alice) - lambda { + expect { alice.destroy - }.should change {alice.invitations_from_me(true).count }.by(-1) + }.to change {alice.invitations_from_me(true).count }.by(-1) end it 'removes invitations to the user' do Invitation.new(:sender => eve, :recipient => alice, :identifier => alice.email, :aspect => eve.aspects.first).save(:validate => false) - lambda { + expect { alice.destroy - }.should change {alice.invitations_to_me(true).count }.by(-1) + }.to change {alice.invitations_to_me(true).count }.by(-1) end it 'removes all service connections' do Services::Facebook.create(:access_token => 'what', :user_id => alice.id) - lambda { + expect { alice.destroy - }.should change { + }.to change { alice.services.count }.by(-1) end @@ -628,13 +628,13 @@ describe User do alice.disable_mail = false alice.save - Workers::Mail::StartedSharing.should_receive(:perform_async).with(alice.id, 'contactrequestid').once + expect(Workers::Mail::StartedSharing).to receive(:perform_async).with(alice.id, 'contactrequestid').once alice.mail(Workers::Mail::StartedSharing, alice.id, 'contactrequestid') end it 'does not enqueue a mail job if the correct corresponding job has a preference entry' do alice.user_preferences.create(:email_type => 'started_sharing') - Workers::Mail::StartedSharing.should_not_receive(:perform_async) + expect(Workers::Mail::StartedSharing).not_to receive(:perform_async) alice.mail(Workers::Mail::StartedSharing, alice.id, 'contactrequestid') end @@ -642,7 +642,7 @@ describe User do alice.disable_mail = true alice.save alice.reload - Workers::Mail::StartedSharing.should_not_receive(:perform_async) + expect(Workers::Mail::StartedSharing).not_to receive(:perform_async) alice.mail(Workers::Mail::StartedSharing, alice.id, 'contactrequestid') end end @@ -656,13 +656,13 @@ describe User do describe "#add_contact_to_aspect" do it 'adds the contact to the aspect' do - lambda { + expect { alice.add_contact_to_aspect(@contact, @new_aspect) - }.should change(@new_aspect.contacts, :count).by(1) + }.to change(@new_aspect.contacts, :count).by(1) end it 'returns true if they are already in the aspect' do - alice.add_contact_to_aspect(@contact, @original_aspect).should be true + expect(alice.add_contact_to_aspect(@contact, @original_aspect)).to be true end end end @@ -679,23 +679,23 @@ describe User do describe '#like_for' do it 'returns the correct like' do - alice.like_for(@message).should == @like - bob.like_for(@message).should == @like2 + expect(alice.like_for(@message)).to eq(@like) + expect(bob.like_for(@message)).to eq(@like2) end it "returns nil if there's no like" do - alice.like_for(@message2).should be_nil + expect(alice.like_for(@message2)).to be_nil end end describe '#liked?' do it "returns true if there's a like" do - alice.liked?(@message).should be true - bob.liked?(@message).should be true + expect(alice.liked?(@message)).to be true + expect(bob.liked?(@message)).to be true end it "returns false if there's no like" do - alice.liked?(@message2).should be false + expect(alice.liked?(@message2)).to be false end end end @@ -705,47 +705,47 @@ describe User do describe "#unconfirmed_email" do it "is nil by default" do - user.unconfirmed_email.should eql(nil) + expect(user.unconfirmed_email).to eql(nil) end it "forces blank to nil" do user.unconfirmed_email = "" user.save! - user.unconfirmed_email.should eql(nil) + expect(user.unconfirmed_email).to eql(nil) end it "is ignored if it equals email" do user.unconfirmed_email = user.email user.save! - user.unconfirmed_email.should eql(nil) + expect(user.unconfirmed_email).to eql(nil) end it "allows change to valid new email" do user.unconfirmed_email = "alice@newmail.com" user.save! - user.unconfirmed_email.should eql("alice@newmail.com") + expect(user.unconfirmed_email).to eql("alice@newmail.com") end end describe "#confirm_email_token" do it "is nil by default" do - user.confirm_email_token.should eql(nil) + expect(user.confirm_email_token).to eql(nil) end it "is autofilled when unconfirmed_email is set to new email" do user.unconfirmed_email = "alice@newmail.com" user.save! - user.confirm_email_token.should_not be_blank - user.confirm_email_token.size.should eql(30) + expect(user.confirm_email_token).not_to be_blank + expect(user.confirm_email_token.size).to eql(30) end it "is set back to nil when unconfirmed_email is empty" do user.unconfirmed_email = "alice@newmail.com" user.save! - user.confirm_email_token.should_not be_blank + expect(user.confirm_email_token).not_to be_blank user.unconfirmed_email = nil user.save! - user.confirm_email_token.should eql(nil) + expect(user.confirm_email_token).to eql(nil) end it "generates new token on every new unconfirmed_email" do @@ -754,21 +754,21 @@ describe User do first_token = user.confirm_email_token user.unconfirmed_email = "alice@andanotherone.com" user.save! - user.confirm_email_token.should_not eql(first_token) - user.confirm_email_token.size.should eql(30) + expect(user.confirm_email_token).not_to eql(first_token) + expect(user.confirm_email_token.size).to eql(30) end end describe '#mail_confirm_email' do it 'enqueues a mail job on user with unconfirmed email' do user.update_attribute(:unconfirmed_email, "alice@newmail.com") - Workers::Mail::ConfirmEmail.should_receive(:perform_async).with(alice.id).once - alice.mail_confirm_email.should eql(true) + expect(Workers::Mail::ConfirmEmail).to receive(:perform_async).with(alice.id).once + expect(alice.mail_confirm_email).to eql(true) end it 'enqueues NO mail job on user without unconfirmed email' do - Workers::Mail::ConfirmEmail.should_not_receive(:perform_async).with(alice.id) - alice.mail_confirm_email.should eql(false) + expect(Workers::Mail::ConfirmEmail).not_to receive(:perform_async).with(alice.id) + expect(alice.mail_confirm_email).to eql(false) end end @@ -779,54 +779,54 @@ describe User do end it 'confirms email and set the unconfirmed_email to email on valid token' do - user.confirm_email(user.confirm_email_token).should eql(true) - user.email.should eql("alice@newmail.com") - user.unconfirmed_email.should eql(nil) - user.confirm_email_token.should eql(nil) + expect(user.confirm_email(user.confirm_email_token)).to eql(true) + expect(user.email).to eql("alice@newmail.com") + expect(user.unconfirmed_email).to eql(nil) + expect(user.confirm_email_token).to eql(nil) end it 'returns false and does not change anything on wrong token' do - user.confirm_email(user.confirm_email_token.reverse).should eql(false) - user.email.should_not eql("alice@newmail.com") - user.unconfirmed_email.should_not eql(nil) - user.confirm_email_token.should_not eql(nil) + expect(user.confirm_email(user.confirm_email_token.reverse)).to eql(false) + expect(user.email).not_to eql("alice@newmail.com") + expect(user.unconfirmed_email).not_to eql(nil) + expect(user.confirm_email_token).not_to eql(nil) end it 'returns false and does not change anything on blank token' do - user.confirm_email("").should eql(false) - user.email.should_not eql("alice@newmail.com") - user.unconfirmed_email.should_not eql(nil) - user.confirm_email_token.should_not eql(nil) + expect(user.confirm_email("")).to eql(false) + expect(user.email).not_to eql("alice@newmail.com") + expect(user.unconfirmed_email).not_to eql(nil) + expect(user.confirm_email_token).not_to eql(nil) end it 'returns false and does not change anything on blank token' do - user.confirm_email(nil).should eql(false) - user.email.should_not eql("alice@newmail.com") - user.unconfirmed_email.should_not eql(nil) - user.confirm_email_token.should_not eql(nil) + expect(user.confirm_email(nil)).to eql(false) + expect(user.email).not_to eql("alice@newmail.com") + expect(user.unconfirmed_email).not_to eql(nil) + expect(user.confirm_email_token).not_to eql(nil) end end context 'on user without unconfirmed email' do it 'returns false and does not change anything on any token' do - user.confirm_email("12345"*6).should eql(false) - user.email.should_not eql("alice@newmail.com") - user.unconfirmed_email.should eql(nil) - user.confirm_email_token.should eql(nil) + expect(user.confirm_email("12345"*6)).to eql(false) + expect(user.email).not_to eql("alice@newmail.com") + expect(user.unconfirmed_email).to eql(nil) + expect(user.confirm_email_token).to eql(nil) end it 'returns false and does not change anything on blank token' do - user.confirm_email("").should eql(false) - user.email.should_not eql("alice@newmail.com") - user.unconfirmed_email.should eql(nil) - user.confirm_email_token.should eql(nil) + expect(user.confirm_email("")).to eql(false) + expect(user.email).not_to eql("alice@newmail.com") + expect(user.unconfirmed_email).to eql(nil) + expect(user.confirm_email_token).to eql(nil) end it 'returns false and does not change anything on blank token' do - user.confirm_email(nil).should eql(false) - user.email.should_not eql("alice@newmail.com") - user.unconfirmed_email.should eql(nil) - user.confirm_email_token.should eql(nil) + expect(user.confirm_email(nil)).to eql(false) + expect(user.email).not_to eql("alice@newmail.com") + expect(user.unconfirmed_email).to eql(nil) + expect(user.confirm_email_token).to eql(nil) end end end @@ -841,14 +841,14 @@ describe User do context "posts" do before do - SignedRetraction.stub(:build).and_return(@retraction) - @retraction.stub(:perform) + allow(SignedRetraction).to receive(:build).and_return(@retraction) + allow(@retraction).to receive(:perform) end it 'sends a retraction' do dispatcher = double - Postzord::Dispatcher.should_receive(:build).with(bob, @retraction, anything()).and_return(dispatcher) - dispatcher.should_receive(:post) + expect(Postzord::Dispatcher).to receive(:build).with(bob, @retraction, anything()).and_return(dispatcher) + expect(dispatcher).to receive(:post) bob.retract(@post) end @@ -859,8 +859,8 @@ describe User do @post.reshares << reshare dispatcher = double - Postzord::Dispatcher.should_receive(:build).with(bob, @retraction, {:additional_subscribers => [person], :services => anything}).and_return(dispatcher) - dispatcher.should_receive(:post) + expect(Postzord::Dispatcher).to receive(:build).with(bob, @retraction, {:additional_subscribers => [person], :services => anything}).and_return(dispatcher) + expect(dispatcher).to receive(:post) bob.retract(@post) end @@ -870,7 +870,7 @@ describe User do describe "#send_reset_password_instructions" do it "queues up a job to send the reset password instructions" do user = FactoryGirl.create :user - Workers::ResetPassword.should_receive(:perform_async).with(user.id) + expect(Workers::ResetPassword).to receive(:perform_async).with(user.id) user.send_reset_password_instructions end end @@ -886,7 +886,7 @@ describe User do [I18n.t('aspects.seed.family'), I18n.t('aspects.seed.friends'), I18n.t('aspects.seed.work'), I18n.t('aspects.seed.acquaintances')].each do |aspect_name| it "creates an aspect named #{aspect_name} for the user" do - user.aspects.find_by_name(aspect_name).should_not be_nil + expect(user.aspects.find_by_name(aspect_name)).not_to be_nil end end end @@ -912,8 +912,8 @@ describe User do AppConfig.settings.autofollow_on_join_user = 'one' wf_double = double - wf_double.should_receive(:fetch) - Webfinger.should_receive(:new).with('one').and_return(wf_double) + expect(wf_double).to receive(:fetch) + expect(Webfinger).to receive(:new).with('one').and_return(wf_double) user.seed_aspects end @@ -923,7 +923,7 @@ describe User do it "should not start sharing with the diasporahq account" do AppConfig.settings.autofollow_on_join = false - Webfinger.should_not_receive(:new) + expect(Webfinger).not_to receive(:new) user.seed_aspects end @@ -939,7 +939,7 @@ describe User do describe "#close_account!" do it 'locks the user out' do @user.close_account! - @user.reload.access_locked?.should be true + expect(@user.reload.access_locked?).to be true end it 'creates an account deletion' do @@ -949,7 +949,7 @@ describe User do end it 'calls person#lock_access!' do - @user.person.should_receive(:lock_access!) + expect(@user.person).to receive(:lock_access!) @user.close_account! end end @@ -957,7 +957,7 @@ describe User do describe "#clear_account!" do it 'resets the password to a random string' do random_pass = "12345678909876543210" - SecureRandom.should_receive(:hex).and_return(random_pass) + expect(SecureRandom).to receive(:hex).and_return(random_pass) @user.clear_account! @user.valid_password?(random_pass) end @@ -969,7 +969,7 @@ describe User do @user.reload attributes.each do |attr| - @user.send(attr.to_sym).should be_blank + expect(@user.send(attr.to_sym)).to be_blank end end end @@ -977,7 +977,7 @@ describe User do describe "#clearable_attributes" do it 'returns the clearable fields' do user = FactoryGirl.create :user - user.send(:clearable_fields).sort.should == %w{ + expect(user.send(:clearable_fields).sort).to eq(%w{ language invitation_token invitation_sent_at @@ -1001,7 +1001,7 @@ describe User do unconfirmed_email confirm_email_token last_seen - }.sort + }.sort) end end end @@ -1025,13 +1025,13 @@ describe User do it "saves with captcha off" do AppConfig.settings.captcha.enable = false - @user.should_receive(:save).and_return(true) + expect(@user).to receive(:save).and_return(true) @user.sign_up end it "saves with captcha on" do AppConfig.settings.captcha.enable = true - @user.should_receive(:save_with_captcha).and_return(true) + expect(@user).to receive(:save_with_captcha).and_return(true) @user.sign_up end end diff --git a/spec/presenters/aspect_presenter_spec.rb b/spec/presenters/aspect_presenter_spec.rb index d38b97f426f30166f8cb0642fc0f0cadba0e6188..ba2bb5b4a137d22d4c426896ab3e39420d92835e 100644 --- a/spec/presenters/aspect_presenter_spec.rb +++ b/spec/presenters/aspect_presenter_spec.rb @@ -7,7 +7,7 @@ describe AspectPresenter do describe '#to_json' do it 'works' do - @presenter.to_json.should be_present + expect(@presenter.to_json).to be_present end end end \ No newline at end of file diff --git a/spec/presenters/o_embed_presenter_spec.rb b/spec/presenters/o_embed_presenter_spec.rb index d343ba96c4d39484b7a84f41e0c88558706b6743..bf8192675d77479c7a76764ff31ca1a5a334833f 100644 --- a/spec/presenters/o_embed_presenter_spec.rb +++ b/spec/presenters/o_embed_presenter_spec.rb @@ -5,31 +5,31 @@ describe OEmbedPresenter do end it 'is a hash' do - @oembed.as_json.should be_a Hash + expect(@oembed.as_json).to be_a Hash end context 'required options from oembed spec' do it 'supports maxheight + maxwidth(required)' do oembed = OEmbedPresenter.new(FactoryGirl.create(:status_message), :maxwidth => 200, :maxheight => 300).as_json - oembed[:width].should == 200 - oembed[:height].should == 300 + expect(oembed[:width]).to eq(200) + expect(oembed[:height]).to eq(300) end end describe '#iframe_html' do it 'passes the height options to post_iframe_url' do - @oembed.should_receive(:post_iframe_url).with(instance_of(Fixnum), instance_of(Hash)) + expect(@oembed).to receive(:post_iframe_url).with(instance_of(Fixnum), instance_of(Hash)) @oembed.iframe_html end end describe '.id_from_url' do it 'takes a long post url and gives you the id' do - OEmbedPresenter.id_from_url('http://localhost:400/posts/1').should == "1" + expect(OEmbedPresenter.id_from_url('http://localhost:400/posts/1')).to eq("1") end it 'takes a short post url and gives you the id' do - OEmbedPresenter.id_from_url('http://localhost:400/p/1').should == "1" + expect(OEmbedPresenter.id_from_url('http://localhost:400/p/1')).to eq("1") end end end \ No newline at end of file diff --git a/spec/presenters/person_presenter_spec.rb b/spec/presenters/person_presenter_spec.rb index 4eb502f0a8f4828fd96b69468ff9d7b21b137c59..433b08bbf960eb3638b0f29f70e114504588a7e8 100644 --- a/spec/presenters/person_presenter_spec.rb +++ b/spec/presenters/person_presenter_spec.rb @@ -7,7 +7,7 @@ describe PersonPresenter do describe "#as_json" do context "with no current_user" do it "returns the user's public information if a user is not logged in" do - PersonPresenter.new(person, nil).as_json.should include(person.as_api_response(:backbone)) + expect(PersonPresenter.new(person, nil).as_json).to include(person.as_api_response(:backbone)) end end @@ -16,16 +16,16 @@ describe PersonPresenter do let(:presenter){ PersonPresenter.new(person, current_user) } it "doesn't share private information when the users aren't connected" do - presenter.as_json.should_not have_key(:location) + expect(presenter.as_json).not_to have_key(:location) end it "has private information when the person is sharing with the current user" do - person.should_receive(:shares_with).with(current_user).and_return(true) - presenter.as_json.should have_key(:location) + expect(person).to receive(:shares_with).with(current_user).and_return(true) + expect(presenter.as_json).to have_key(:location) end it "returns the user's private information if a user is logged in as herself" do - PersonPresenter.new(current_user.person, current_user).as_json.should have_key(:location) + expect(PersonPresenter.new(current_user.person, current_user).as_json).to have_key(:location) end end end diff --git a/spec/presenters/post_presenter_spec.rb b/spec/presenters/post_presenter_spec.rb index e487465e14dbe761a7d8d7fff5353bfb80254741..293f0337c545bb250c75f9a1aa3d61b4ed297065 100644 --- a/spec/presenters/post_presenter_spec.rb +++ b/spec/presenters/post_presenter_spec.rb @@ -9,38 +9,38 @@ describe PostPresenter do end it 'takes a post and an optional user' do - @presenter.should_not be_nil + expect(@presenter).not_to be_nil end describe '#as_json' do it 'works with a user' do - @presenter.as_json.should be_a Hash + expect(@presenter.as_json).to be_a Hash end it 'works without a user' do - @unauthenticated_presenter.as_json.should be_a Hash + expect(@unauthenticated_presenter.as_json).to be_a Hash end end describe '#user_like' do it 'includes the users like' do bob.like!(@sm) - @presenter.user_like.should be_present + expect(@presenter.user_like).to be_present end it 'is nil if the user is not authenticated' do - @unauthenticated_presenter.user_like.should be_nil + expect(@unauthenticated_presenter.user_like).to be_nil end end describe '#user_reshare' do it 'includes the users reshare' do bob.reshare!(@sm) - @presenter.user_reshare.should be_present + expect(@presenter.user_reshare).to be_present end it 'is nil if the user is not authenticated' do - @unauthenticated_presenter.user_reshare.should be_nil + expect(@unauthenticated_presenter.user_reshare).to be_nil end end @@ -68,7 +68,7 @@ describe PostPresenter do context 'with posts with text' do it "delegates to message.title" do message = double(present?: true) - message.should_receive(:title) + expect(message).to receive(:title) @presenter.post = double(message: message) @presenter.title end @@ -78,7 +78,7 @@ describe PostPresenter do it ' displays a messaage with the post class' do @sm = double(message: double(present?: false), author: bob.person, author_name: bob.person.name) @presenter.post = @sm - @presenter.title.should == "A post from #{@sm.author.name}" + expect(@presenter.title).to eq("A post from #{@sm.author.name}") end end end @@ -86,7 +86,7 @@ describe PostPresenter do describe '#poll' do it 'works without a user' do presenter = PostPresenter.new(@sm_with_poll) - presenter.as_json.should be_a(Hash) + expect(presenter.as_json).to be_a(Hash) end end end diff --git a/spec/presenters/service_presenter_spec.rb b/spec/presenters/service_presenter_spec.rb index 62c959af9e0cdd32d551d9cdecca1f28cde98ac7..046645552c83d9c86eff99bfad3e0cf86eabbc57 100644 --- a/spec/presenters/service_presenter_spec.rb +++ b/spec/presenters/service_presenter_spec.rb @@ -4,7 +4,7 @@ describe ServicePresenter do describe '#as_json' do it 'includes the provider name of the json' do presenter = ServicePresenter.new(double(:provider => "fakebook")) - presenter.as_json[:provider].should == 'fakebook' + expect(presenter.as_json[:provider]).to eq('fakebook') end end end \ No newline at end of file diff --git a/spec/presenters/statistics_presenter_spec.rb b/spec/presenters/statistics_presenter_spec.rb index e1d17103bf1eaac3c94f8f1bf5368122eac35a39..61359752efab840d83ca9e5a65503e5346445063 100644 --- a/spec/presenters/statistics_presenter_spec.rb +++ b/spec/presenters/statistics_presenter_spec.rb @@ -7,8 +7,8 @@ describe StatisticsPresenter do describe '#as_json' do it 'works' do - @presenter.as_json.should be_present - @presenter.as_json.should be_a Hash + expect(@presenter.as_json).to be_present + expect(@presenter.as_json).to be_a Hash end end @@ -19,12 +19,12 @@ describe StatisticsPresenter do AppConfig.privacy.statistics.post_counts = false AppConfig.privacy.statistics.comment_counts = false AppConfig.services = {"facebook" => nil} - @presenter.as_json.should == { + expect(@presenter.as_json).to eq({ "name" => AppConfig.settings.pod_name, "version" => AppConfig.version_string, "registrations_open" => AppConfig.settings.enable_registrations, "facebook" => false - } + }) end context 'when services are enabled' do @@ -41,7 +41,7 @@ describe StatisticsPresenter do end it 'provides generic pod data and counts in json' do - @presenter.as_json.should == { + expect(@presenter.as_json).to eq({ "name" => AppConfig.settings.pod_name, "version" => AppConfig.version_string, "registrations_open" => AppConfig.settings.enable_registrations, @@ -54,7 +54,7 @@ describe StatisticsPresenter do "twitter" => true, "tumblr" => false, "wordpress" => false - } + }) end end diff --git a/spec/presenters/user_presenter_spec.rb b/spec/presenters/user_presenter_spec.rb index 04b57b4c17dd4d66bf3ca94cfa2fe5f2f27086b8..aa9ecf7ce81f5d4f7e39e236432072846abfa12d 100644 --- a/spec/presenters/user_presenter_spec.rb +++ b/spec/presenters/user_presenter_spec.rb @@ -7,31 +7,31 @@ describe UserPresenter do describe '#to_json' do it 'works' do - @presenter.to_json.should be_present + expect(@presenter.to_json).to be_present end end describe '#aspects' do it 'provides an array of the jsonified aspects' do aspect = bob.aspects.first - @presenter.aspects.first[:id].should == aspect.id - @presenter.aspects.first[:name].should == aspect.name + expect(@presenter.aspects.first[:id]).to eq(aspect.id) + expect(@presenter.aspects.first[:name]).to eq(aspect.name) end end describe '#services' do it 'provides an array of jsonifed services' do fakebook = double(:provider => 'fakebook') - bob.stub(:services).and_return([fakebook]) - @presenter.services.should include(:provider => 'fakebook') + allow(bob).to receive(:services).and_return([fakebook]) + expect(@presenter.services).to include(:provider => 'fakebook') end end describe '#configured_services' do it 'displays a list of the users configured services' do fakebook = double(:provider => 'fakebook') - bob.stub(:services).and_return([fakebook]) - @presenter.configured_services.should include("fakebook") + allow(bob).to receive(:services).and_return([fakebook]) + expect(@presenter.configured_services).to include("fakebook") end end end diff --git a/spec/shared_behaviors/account_deletion.rb b/spec/shared_behaviors/account_deletion.rb index 4d5d3c46d96c66a4824841d954bafb34eea589fc..027442b14099e44dfb0fe00ea0c9ccebe7262b76 100644 --- a/spec/shared_behaviors/account_deletion.rb +++ b/spec/shared_behaviors/account_deletion.rb @@ -6,34 +6,34 @@ require 'spec_helper' shared_examples_for 'it removes the person associations' do it "removes all of the person's posts" do - Post.where(:author_id => @person.id).count.should == 0 + expect(Post.where(:author_id => @person.id).count).to eq(0) end it 'deletes all person contacts' do - Contact.where(:person_id => @person.id).should be_empty + expect(Contact.where(:person_id => @person.id)).to be_empty end it 'deletes all mentions' do - @person.mentions.should be_empty + expect(@person.mentions).to be_empty end it "removes all of the person's photos" do - Photo.where(:author_id => @person.id).should be_empty + expect(Photo.where(:author_id => @person.id)).to be_empty end it 'sets the person object as closed and the profile is cleared' do - @person.reload.closed_account.should be true + expect(@person.reload.closed_account).to be true - @person.profile.reload.first_name.should be_blank - @person.profile.reload.last_name.should be_blank + expect(@person.profile.reload.first_name).to be_blank + expect(@person.profile.reload.last_name).to be_blank end it 'deletes only the converersation visibility for the deleted user' do - ConversationVisibility.where(:person_id => alice.person.id).should_not be_empty - ConversationVisibility.where(:person_id => @person.id).should be_empty + expect(ConversationVisibility.where(:person_id => alice.person.id)).not_to be_empty + expect(ConversationVisibility.where(:person_id => @person.id)).to be_empty end it "deletes the share visibilities on the person's posts" do - ShareVisibility.for_contacts_of_a_person(@person).should be_empty + expect(ShareVisibility.for_contacts_of_a_person(@person)).to be_empty end end diff --git a/spec/shared_behaviors/relayable.rb b/spec/shared_behaviors/relayable.rb index fdd4b484e98a7e53067da41ee4be71ab590425f5..6973f6e1f6d3bd49ba693fbd3619d18ea95d63a5 100644 --- a/spec/shared_behaviors/relayable.rb +++ b/spec/shared_behaviors/relayable.rb @@ -12,7 +12,7 @@ shared_examples_for "it is relayable" do relayable = build_object relayable.save if relayable.parent.respond_to?(:interacted_at) #I'm sorry. - relayable.parent.interacted_at.to_i.should == relayable.created_at.to_i + expect(relayable.parent.interacted_at.to_i).to eq(relayable.created_at.to_i) end end end @@ -27,14 +27,14 @@ shared_examples_for "it is relayable" do end it "is invalid" do - @relayable.should_not be_valid - @relayable.errors[:author_id].size.should == 1 + expect(@relayable).not_to be_valid + expect(@relayable.errors[:author_id].size).to eq(1) end it "sends a retraction for the object" do skip 'need to figure out how to test this' - RelayableRetraction.should_receive(:build) - Postzord::Dispatcher.should_receive(:build) + expect(RelayableRetraction).to receive(:build) + expect(Postzord::Dispatcher).to receive(:build) @relayable.valid? end @@ -49,7 +49,7 @@ shared_examples_for "it is relayable" do relayable = build_object relayable.save! bob.blocks.create(:person => alice.person) - relayable.should be_valid + expect(relayable).to be_valid end end end @@ -58,26 +58,26 @@ shared_examples_for "it is relayable" do context 'encryption' do describe '#parent_author_signature' do it 'should sign the object if the user is the post author' do - @object_by_parent_author.verify_parent_author_signature.should be true + expect(@object_by_parent_author.verify_parent_author_signature).to be true end it 'does not sign as the parent author is not parent' do @object_by_recipient.author_signature = @object_by_recipient.send(:sign_with_key, @local_leia.encryption_key) - @object_by_recipient.verify_parent_author_signature.should be false + expect(@object_by_recipient.verify_parent_author_signature).to be false end it 'should verify a object made on a remote post by a different contact' do @object_by_recipient.author_signature = @object_by_recipient.send(:sign_with_key, @local_leia.encryption_key) @object_by_recipient.parent_author_signature = @object_by_recipient.send(:sign_with_key, @local_luke.encryption_key) - @object_by_recipient.verify_parent_author_signature.should be true + expect(@object_by_recipient.verify_parent_author_signature).to be true end end describe '#author_signature' do it 'should sign as the object author' do - @object_on_remote_parent.signature_valid?.should be true - @object_by_parent_author.signature_valid?.should be true - @object_by_recipient.signature_valid?.should be true + expect(@object_on_remote_parent.signature_valid?).to be true + expect(@object_by_parent_author.signature_valid?).to be true + expect(@object_by_recipient.signature_valid?).to be true end end end @@ -93,36 +93,36 @@ shared_examples_for "it is relayable" do it 'does not process if post_creator_signature is invalid' do @object_by_parent_author.delete # remove object from db so we set a creator sig @dup_object_by_parent_author.parent_author_signature = "dsfadsfdsa" - @dup_object_by_parent_author.receive(@local_leia, @local_luke.person).should == nil + expect(@dup_object_by_parent_author.receive(@local_leia, @local_luke.person)).to eq(nil) end it 'signs when the person receiving is the parent author' do @object_by_recipient.save @object_by_recipient.receive(@local_luke, @local_leia.person) - @object_by_recipient.reload.parent_author_signature.should_not be_blank + expect(@object_by_recipient.reload.parent_author_signature).not_to be_blank end it 'dispatches when the person receiving is the parent author' do p = Postzord::Dispatcher.build(@local_luke, @object_by_recipient) - p.should_receive(:post) - p.class.stub(:new).and_return(p) + expect(p).to receive(:post) + allow(p.class).to receive(:new).and_return(p) @object_by_recipient.receive(@local_luke, @local_leia.person) end it 'calls after_receive callback' do - @object_by_recipient.should_receive(:after_receive) - @object_by_recipient.class.stub(:where).and_return([@object_by_recipient]) + expect(@object_by_recipient).to receive(:after_receive) + allow(@object_by_recipient.class).to receive(:where).and_return([@object_by_recipient]) @object_by_recipient.receive(@local_luke, @local_leia.person) end end describe '#subscribers' do it 'returns the posts original audience, if the post is owned by the user' do - @object_by_parent_author.subscribers(@local_luke).map(&:id).should =~ [@local_leia.person, @remote_raphael].map(&:id) + expect(@object_by_parent_author.subscribers(@local_luke).map(&:id)).to match_array([@local_leia.person, @remote_raphael].map(&:id)) end it 'returns the owner of the original post, if the user owns the object' do - @object_by_recipient.subscribers(@local_leia).map(&:id).should =~ [@local_luke.person].map(&:id) + expect(@object_by_recipient.subscribers(@local_leia).map(&:id)).to match_array([@local_luke.person].map(&:id)) end end end diff --git a/spec/shared_behaviors/stream.rb b/spec/shared_behaviors/stream.rb index 9207be34e25e9c9f0424bfc16b8d7d99feaeb1f3..d4923358849c244c5c1ca9292ad3794160f0b030 100644 --- a/spec/shared_behaviors/stream.rb +++ b/spec/shared_behaviors/stream.rb @@ -3,41 +3,41 @@ require 'spec_helper' shared_examples_for 'it is a stream' do context 'required methods for display' do it '#title' do - @stream.title.should_not be_nil + expect(@stream.title).not_to be_nil end it '#posts' do - @stream.posts.should_not be_nil + expect(@stream.posts).not_to be_nil end it '#people' do - @stream.people.should_not be_nil + expect(@stream.people).not_to be_nil end it '#publisher_opts' do - @stream.send(:publisher_opts).should_not be_nil + expect(@stream.send(:publisher_opts)).not_to be_nil end it 'has a #contacts title' do - @stream.contacts_title.should_not be_nil + expect(@stream.contacts_title).not_to be_nil end it 'has a contacts link' do - @stream.contacts_link.should_not be_nil + expect(@stream.contacts_link).not_to be_nil end it 'should make the stream a time object' do @stream.max_time = 123 - @stream.max_time.should be_a(Time) + expect(@stream.max_time).to be_a(Time) end it 'should always have an order (default created_at)' do @stream.order=nil - @stream.order.should_not be_nil + expect(@stream.order).not_to be_nil end it 'initializes a publisher' do - @stream.publisher.should be_a(Publisher) + expect(@stream.publisher).to be_a(Publisher) end end end diff --git a/spec/shared_behaviors/taggable.rb b/spec/shared_behaviors/taggable.rb index 95b202352168499aa451982b4d1b6f7e68cf47f8..0eddd92cbb5a36d92cc184e60cb04490de00d783 100644 --- a/spec/shared_behaviors/taggable.rb +++ b/spec/shared_behaviors/taggable.rb @@ -21,18 +21,18 @@ shared_examples_for "it is taggable" do end it "supports non-ascii characters" do - @object.tags(true).map(&:name).should include('vöglein') + expect(@object.tags(true).map(&:name)).to include('vöglein') end it 'links each tag' do formatted_string = Diaspora::Taggable.format_tags(@str) - formatted_string.should include(tag_link('what')) - formatted_string.should include(tag_link('hey')) - formatted_string.should include(tag_link('vöglein')) + expect(formatted_string).to include(tag_link('what')) + expect(formatted_string).to include(tag_link('hey')) + expect(formatted_string).to include(tag_link('vöglein')) end it 'responds to plain_text' do - Diaspora::Taggable.format_tags(@str, :plain_text => true).should == @str + expect(Diaspora::Taggable.format_tags(@str, :plain_text => true)).to eq(@str) end it "doesn't mangle text when tags are involved" do @@ -78,7 +78,7 @@ shared_examples_for "it is taggable" do } expected.each do |input,output| - Diaspora::Taggable.format_tags(input).should == output + expect(Diaspora::Taggable.format_tags(input)).to eq(output) end end end @@ -87,10 +87,10 @@ shared_examples_for "it is taggable" do it 'builds the tags' do @object.send(@object.class.field_with_tags_setter, '#what') @object.build_tags - @object.tag_list.should == ['what'] - lambda { + expect(@object.tag_list).to eq(['what']) + expect { @object.save - }.should change{@object.tags.count}.by(1) + }.to change{@object.tags.count}.by(1) end end @@ -100,7 +100,7 @@ shared_examples_for "it is taggable" do arr = ['what', 'hey', 'that', 'THATWASMYBIKE', 'vöglein', '135440we', 'abc', 'h', 'ok', 'see', 're'] @object.send(@object.class.field_with_tags_setter, str) - @object.tag_strings.should =~ arr + expect(@object.tag_strings).to match_array(arr) end it 'extracts tags despite surrounding text' do @@ -143,7 +143,7 @@ shared_examples_for "it is taggable" do expected.each do |text,hashtag| @object.send @object.class.field_with_tags_setter, text - @object.tag_strings.should == [hashtag].compact + expect(@object.tag_strings).to eq([hashtag].compact) end end @@ -152,7 +152,7 @@ shared_examples_for "it is taggable" do arr = ['what','whaaaaaaaaaat'] @object.send(@object.class.field_with_tags_setter, str) - @object.tag_strings.should =~ arr + expect(@object.tag_strings).to match_array(arr) end it 'is case insensitive' do @@ -160,7 +160,7 @@ shared_examples_for "it is taggable" do arr = ['what'] @object.send(@object.class.field_with_tags_setter, str) - @object.tag_strings.should =~ arr + expect(@object.tag_strings).to match_array(arr) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f67a0335443db544c7d9ee9874ee066a7b2df4c..63c056554227e750243a7fc2855323e4e76fe106 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -83,8 +83,8 @@ prefork = proc do stub_request(:post, "https://pubsubhubbub.appspot.com/") disable_typhoeus $process_queue = false - Postzord::Dispatcher::Public.any_instance.stub(:deliver_to_remote) - Postzord::Dispatcher::Private.any_instance.stub(:deliver_to_remote) + allow_any_instance_of(Postzord::Dispatcher::Public).to receive(:deliver_to_remote) + allow_any_instance_of(Postzord::Dispatcher::Private).to receive(:deliver_to_remote) end diff --git a/spec/workers/delete_account_spec.rb b/spec/workers/delete_account_spec.rb index 5f374cfd3e570748e28440c73d372dee3dbb7b81..dd604f7d84b04c03b77ccee2a4cb72e40890fbe2 100644 --- a/spec/workers/delete_account_spec.rb +++ b/spec/workers/delete_account_spec.rb @@ -8,8 +8,8 @@ describe Workers::DeleteAccount do describe '#perform' do it 'performs the account deletion' do account_deletion = double - AccountDeletion.stub(:find).and_return(account_deletion) - account_deletion.should_receive(:perform!) + allow(AccountDeletion).to receive(:find).and_return(account_deletion) + expect(account_deletion).to receive(:perform!) Workers::DeleteAccount.new.perform(1) end diff --git a/spec/workers/delete_post_from_service_spec.rb b/spec/workers/delete_post_from_service_spec.rb index b941335c1021d6698d4b26239edc934db742c5ee..75e902034428094be3235a4333d9999d804cd222 100644 --- a/spec/workers/delete_post_from_service_spec.rb +++ b/spec/workers/delete_post_from_service_spec.rb @@ -9,8 +9,8 @@ describe Workers::DeletePostFromService do it 'calls service#delete_post with given service' do m = double() url = "foobar" - m.should_receive(:delete_post) - Service.stub(:find_by_id).and_return(m) + expect(m).to receive(:delete_post) + allow(Service).to receive(:find_by_id).and_return(m) Workers::DeletePostFromService.new.perform("123", @post.id.to_s) end end diff --git a/spec/workers/fetch_profile_photo_spec.rb b/spec/workers/fetch_profile_photo_spec.rb index 24afa1d705775f9dc50a592ba4364cd7e5eded53..0b118ce7e4fdf1bfc41d6ad9fb0b0ba13791c8fd 100644 --- a/spec/workers/fetch_profile_photo_spec.rb +++ b/spec/workers/fetch_profile_photo_spec.rb @@ -7,36 +7,36 @@ describe Workers::FetchProfilePhoto do @url = "https://service.com/user/profile_image" - @service.stub(:profile_photo_url).and_return(@url) - @user.stub(:update_profile) + allow(@service).to receive(:profile_photo_url).and_return(@url) + allow(@user).to receive(:update_profile) - User.stub(:find).and_return(@user) - Service.stub(:find).and_return(@service) + allow(User).to receive(:find).and_return(@user) + allow(Service).to receive(:find).and_return(@service) @photo_double = double - @photo_double.stub(:save!).and_return(true) - @photo_double.stub(:url).and_return("image.jpg") + allow(@photo_double).to receive(:save!).and_return(true) + allow(@photo_double).to receive(:url).and_return("image.jpg") end it 'saves the profile image' do - @photo_double.should_receive(:save!).and_return(true) - Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_double) + expect(@photo_double).to receive(:save!).and_return(true) + expect(Photo).to receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_double) Workers::FetchProfilePhoto.new.perform(@user.id, @service.id) end context "service does not have a profile_photo_url" do it "does nothing without fallback" do - @service.stub(:profile_photo_url).and_return(nil) - Photo.should_not_receive(:diaspora_initialize) + allow(@service).to receive(:profile_photo_url).and_return(nil) + expect(Photo).not_to receive(:diaspora_initialize) Workers::FetchProfilePhoto.new.perform(@user.id, @service.id) end it "fetches fallback if it's provided" do - @photo_double.should_receive(:save!).and_return(true) - @service.stub(:profile_photo_url).and_return(nil) - Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_double) + expect(@photo_double).to receive(:save!).and_return(true) + allow(@service).to receive(:profile_photo_url).and_return(nil) + expect(Photo).to receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_double) Workers::FetchProfilePhoto.new.perform(@user.id, @service.id, "https://service.com/fallback_lowres.jpg") end @@ -44,10 +44,10 @@ describe Workers::FetchProfilePhoto do it 'updates the profile' do - @photo_double.stub(:url).and_return("large.jpg", "medium.jpg", "small.jpg") + allow(@photo_double).to receive(:url).and_return("large.jpg", "medium.jpg", "small.jpg") - Photo.should_receive(:diaspora_initialize).and_return(@photo_double) - @user.should_receive(:update_profile).with(hash_including({ + expect(Photo).to receive(:diaspora_initialize).and_return(@photo_double) + expect(@user).to receive(:update_profile).with(hash_including({ :image_url => "large.jpg", :image_url_medium => "medium.jpg", :image_url_small => "small.jpg" diff --git a/spec/workers/gather_o_embed_data_spec.rb b/spec/workers/gather_o_embed_data_spec.rb index 1593ed4e07a04b0f41abead537edb8ec74ea2564..97177d7deac2e7f5c951788366e754bbd3bf7c90 100644 --- a/spec/workers/gather_o_embed_data_spec.rb +++ b/spec/workers/gather_o_embed_data_spec.rb @@ -32,7 +32,7 @@ describe Workers::GatherOEmbedData do it 'requests not data from the internet' do Workers::GatherOEmbedData.new.perform(@status_message.id, @flickr_photo_url) - a_request(:get, @flickr_oembed_get_request).should have_been_made + expect(a_request(:get, @flickr_oembed_get_request)).to have_been_made end it 'requests not data from the internet only once' do @@ -40,7 +40,7 @@ describe Workers::GatherOEmbedData do Workers::GatherOEmbedData.new.perform(@status_message.id, @flickr_photo_url) end - a_request(:get, @flickr_oembed_get_request).should have_been_made.times(1) + expect(a_request(:get, @flickr_oembed_get_request)).to have_been_made.times(1) end it 'creates one cache entry' do @@ -48,16 +48,16 @@ describe Workers::GatherOEmbedData do expected_data = @flickr_oembed_data expected_data['trusted_endpoint_url'] = @flickr_oembed_url - OEmbedCache.find_by_url(@flickr_photo_url).data.should == expected_data + expect(OEmbedCache.find_by_url(@flickr_photo_url).data).to eq(expected_data) Workers::GatherOEmbedData.new.perform(@status_message.id, @flickr_photo_url) - OEmbedCache.where(url: @flickr_photo_url).count.should == 1 + expect(OEmbedCache.where(url: @flickr_photo_url).count).to eq(1) end it 'creates no cache entry for unsupported pages' do Workers::GatherOEmbedData.new.perform(@status_message.id, @no_oembed_url) - OEmbedCache.find_by_url(@no_oembed_url).should be_nil + expect(OEmbedCache.find_by_url(@no_oembed_url)).to be_nil end it 'gracefully handles a deleted post' do diff --git a/spec/workers/gather_open_graph_data_spec.rb b/spec/workers/gather_open_graph_data_spec.rb index dbe53ff81ca8e374bd1dcb82010d479a2d8717d7..7c2397e4feaa432c8abc02d87bb48976a66c7ff9 100644 --- a/spec/workers/gather_open_graph_data_spec.rb +++ b/spec/workers/gather_open_graph_data_spec.rb @@ -28,7 +28,7 @@ describe Workers::GatherOpenGraphData do it 'requests not data from the internet' do Workers::GatherOpenGraphData.new.perform(@status_message.id, @ogsite_url) - a_request(:get, @ogsite_url).should have_been_made + expect(a_request(:get, @ogsite_url)).to have_been_made end it 'requests not data from the internet only once' do @@ -36,7 +36,7 @@ describe Workers::GatherOpenGraphData do Workers::GatherOpenGraphData.new.perform(@status_message.id, @ogsite_url) end - a_request(:get, @ogsite_url).should have_been_made.times(1) + expect(a_request(:get, @ogsite_url)).to have_been_made.times(1) end it 'creates one cache entry' do @@ -44,20 +44,20 @@ describe Workers::GatherOpenGraphData do ogc = OpenGraphCache.find_by_url(@ogsite_url) - ogc.title.should == @ogsite_title - ogc.ob_type.should == @ogsite_type - ogc.image.should == @ogsite_url + @ogsite_image - ogc.url.should == @ogsite_url - ogc.description.should == @ogsite_description + expect(ogc.title).to eq(@ogsite_title) + expect(ogc.ob_type).to eq(@ogsite_type) + expect(ogc.image).to eq(@ogsite_url + @ogsite_image) + expect(ogc.url).to eq(@ogsite_url) + expect(ogc.description).to eq(@ogsite_description) Workers::GatherOpenGraphData.new.perform(@status_message.id, @ogsite_url) - OpenGraphCache.where(url: @ogsite_url).count.should == 1 + expect(OpenGraphCache.where(url: @ogsite_url).count).to eq(1) end it 'creates no cache entry for unsupported pages' do Workers::GatherOpenGraphData.new.perform(@status_message.id, @no_open_graph_url) - OpenGraphCache.find_by_url(@no_open_graph_url).should be_nil + expect(OpenGraphCache.find_by_url(@no_open_graph_url)).to be_nil end it 'gracefully handles a deleted post' do diff --git a/spec/workers/http_multi_spec.rb b/spec/workers/http_multi_spec.rb index b78088e8f10fedd8699396ac99d96d4fb4c8b70d..05e70d2f24fe20301b09423b028c6169306c759c 100644 --- a/spec/workers/http_multi_spec.rb +++ b/spec/workers/http_multi_spec.rb @@ -16,11 +16,11 @@ describe Workers::HttpMulti do @post_xml = Base64.encode64 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH" @hydra = Typhoeus::Hydra.new - Typhoeus::Hydra.stub(:new).and_return(@hydra) + allow(Typhoeus::Hydra).to receive(:new).and_return(@hydra) @salmon = Salmon::EncryptedSlap.create_by_user_and_activity bob, Base64.decode64(@post_xml) - Salmon::EncryptedSlap.stub(:create_by_user_and_activity).and_return @salmon + allow(Salmon::EncryptedSlap).to receive(:create_by_user_and_activity).and_return @salmon @body = "encrypted things" - @salmon.stub(:xml_for).and_return @body + allow(@salmon).to receive(:xml_for).and_return @body @response = Typhoeus::Response.new( code: 200, @@ -57,8 +57,8 @@ describe Workers::HttpMulti do Typhoeus.stub(person.receive_url).and_return @response end - @hydra.should_receive(:queue).twice - @hydra.should_receive(:run).once + expect(@hydra).to receive(:queue).twice + expect(@hydra).to receive(:run).once Workers::HttpMulti.new.perform bob.id, @post_xml, @people.map(&:id), "Postzord::Dispatcher::Private" end @@ -68,7 +68,7 @@ describe Workers::HttpMulti do Typhoeus.stub(person.receive_url).and_return @failed_response - Workers::HttpMulti.should_receive(:perform_in).with(1.hour, bob.id, @post_xml, [person.id], anything, 1).once + expect(Workers::HttpMulti).to receive(:perform_in).with(1.hour, bob.id, @post_xml, [person.id], anything, 1).once Workers::HttpMulti.new.perform bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private" end @@ -77,7 +77,7 @@ describe Workers::HttpMulti do Typhoeus.stub(person.receive_url).and_return @unable_to_resolve_response - Workers::HttpMulti.should_receive(:perform_in).with(1.hour, bob.id, @post_xml, [person.id], anything, 1).once + expect(Workers::HttpMulti).to receive(:perform_in).with(1.hour, bob.id, @post_xml, [person.id], anything, 1).once Workers::HttpMulti.new.perform bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private" end @@ -86,7 +86,7 @@ describe Workers::HttpMulti do Typhoeus.stub(person.receive_url).and_return @ssl_error_response - Workers::HttpMulti.should_not_receive(:perform_in) + expect(Workers::HttpMulti).not_to receive(:perform_in) Workers::HttpMulti.new.perform bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private" end @@ -95,7 +95,7 @@ describe Workers::HttpMulti do Typhoeus.stub(person.receive_url).and_return @failed_response - Workers::HttpMulti.should_not_receive :perform_in + expect(Workers::HttpMulti).not_to receive :perform_in Workers::HttpMulti.new.perform bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private", 3 end @@ -103,7 +103,7 @@ describe Workers::HttpMulti do person = @people.first Typhoeus.stub(person.receive_url).and_return @response - @salmon.should_receive(:xml_for).and_return @body + expect(@salmon).to receive(:xml_for).and_return @body Workers::HttpMulti.new.perform bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private" end @@ -124,7 +124,7 @@ describe Workers::HttpMulti do Workers::HttpMulti.new.perform bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private" person.reload - person.url.should == "https://remote.net/" + expect(person.url).to eq("https://remote.net/") end it 'only sends to users with valid RSA keys' do @@ -138,7 +138,7 @@ describe Workers::HttpMulti do Typhoeus.stub(person.receive_url).and_return @response Typhoeus.stub(@people[1].receive_url).and_return @response - @hydra.should_receive(:queue).once + expect(@hydra).to receive(:queue).once Workers::HttpMulti.new.perform bob.id, @post_xml, @people.map(&:id), "Postzord::Dispatcher::Private" end end diff --git a/spec/workers/mail/invite_email_spec.rb b/spec/workers/mail/invite_email_spec.rb index ca0a2d6e2c89bf7f597cb6f5f7ea3211c8479d1e..6c94460e949cae4092d8164f3cdc44aec63cb2c7 100644 --- a/spec/workers/mail/invite_email_spec.rb +++ b/spec/workers/mail/invite_email_spec.rb @@ -6,9 +6,9 @@ describe Workers::Mail::InviteEmail do let(:email_inviter) { double('EmailInviter') } it 'creates a new email inviter' do - EmailInviter.should_receive(:new).with(emails, alice, message: message) + expect(EmailInviter).to receive(:new).with(emails, alice, message: message) .and_return(email_inviter) - email_inviter.should_receive(:send!) + expect(email_inviter).to receive(:send!) Workers::Mail::InviteEmail.new.perform(emails, alice, message: message) end end diff --git a/spec/workers/mail/mentioned_spec.rb b/spec/workers/mail/mentioned_spec.rb index 332f8cddafb61e74b743fdee3e8ffe22b145537a..ac7e787b249fd055432a249d513e26a684760c6b 100644 --- a/spec/workers/mail/mentioned_spec.rb +++ b/spec/workers/mail/mentioned_spec.rb @@ -12,8 +12,8 @@ describe Workers::Mail::Mentioned do m = Mention.new(:person => user.person, :post=> sm) mail_double = double() - mail_double.should_receive(:deliver) - Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_double) + expect(mail_double).to receive(:deliver) + expect(Notifier).to receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_double) Workers::Mail::Mentioned.new.perform(user.id, sm.author.id, m.id) end diff --git a/spec/workers/mail/private_message_spec.rb b/spec/workers/mail/private_message_spec.rb index 3fa271342a75fd19adb4343845e57a814fe29f98..9ee1c0fbf15e34778902d8830524261d7cf3c9ab 100644 --- a/spec/workers/mail/private_message_spec.rb +++ b/spec/workers/mail/private_message_spec.rb @@ -18,8 +18,8 @@ describe Workers::Mail::PrivateMessage do message = cnv.messages.first mail_double = double() - mail_double.should_receive(:deliver) - Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_double) + expect(mail_double).to receive(:deliver) + expect(Notifier).to receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_double) Workers::Mail::Mentioned.new.perform(user2.id, user1.person.id, message.id) end diff --git a/spec/workers/mail/reshared_spec.rb b/spec/workers/mail/reshared_spec.rb index 478cd5a96799cedbf907a79cb75fb5b90cae20bc..016d75b43c575bcc8d4fed9a6f8ce2da9c6f817f 100644 --- a/spec/workers/mail/reshared_spec.rb +++ b/spec/workers/mail/reshared_spec.rb @@ -11,8 +11,8 @@ describe Workers::Mail::Reshared do reshare = FactoryGirl.build(:reshare, :author => alice.person, :root=> sm) mail_double = double() - mail_double.should_receive(:deliver) - Notifier.should_receive(:reshared).with(bob.id, reshare.author.id, reshare.id).and_return(mail_double) + expect(mail_double).to receive(:deliver) + expect(Notifier).to receive(:reshared).with(bob.id, reshare.author.id, reshare.id).and_return(mail_double) Workers::Mail::Reshared.new.perform(bob.id, reshare.author.id, reshare.id) end diff --git a/spec/workers/notify_local_users_spec.rb b/spec/workers/notify_local_users_spec.rb index b058d0f77a4eb89fb8349b075f102e4c839f5546..6f89e1ed5e38c3bad2cd8568289e6f6ee430440d 100644 --- a/spec/workers/notify_local_users_spec.rb +++ b/spec/workers/notify_local_users_spec.rb @@ -10,9 +10,9 @@ describe Workers::NotifyLocalUsers do person = FactoryGirl.create :person post = FactoryGirl.create :status_message - StatusMessage.should_receive(:find_by_id).with(post.id).and_return(post) + expect(StatusMessage).to receive(:find_by_id).with(post.id).and_return(post) #User.should_receive(:where).and_return([alice, eve]) - Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)).twice + expect(Notification).to receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)).twice Workers::NotifyLocalUsers.new.perform([alice.id, eve.id], post.class.to_s, post.id, person.id) end diff --git a/spec/workers/post_to_service_spec.rb b/spec/workers/post_to_service_spec.rb index 4ba8c476765049f5397d956dabb112ecfb2555cf..e75578079a1b6dac904a12e09a7b1665fe95323f 100644 --- a/spec/workers/post_to_service_spec.rb +++ b/spec/workers/post_to_service_spec.rb @@ -5,11 +5,11 @@ describe Workers::PostToService do user = alice aspect = user.aspects.create(:name => "yeah") post = user.post(:status_message, :text => 'foo', :to => aspect.id) - User.stub(:find_by_id).with(user.id.to_s).and_return(user) + allow(User).to receive(:find_by_id).with(user.id.to_s).and_return(user) m = double() url = "foobar" - m.should_receive(:post).with(anything, url) - Service.stub(:find_by_id).and_return(m) + expect(m).to receive(:post).with(anything, url) + allow(Service).to receive(:find_by_id).and_return(m) Workers::PostToService.new.perform("123", post.id.to_s, url) end end diff --git a/spec/workers/process_photo_spec.rb b/spec/workers/process_photo_spec.rb index 5b07b4316c619240486658ff28e51cc9f54e2fc1..8294902cae558ad2b37e66d02f4106e743de770e 100644 --- a/spec/workers/process_photo_spec.rb +++ b/spec/workers/process_photo_spec.rb @@ -12,14 +12,14 @@ describe Workers::ProcessPhoto do end it 'saves the processed image' do - @saved_photo.processed_image.path.should be_nil + expect(@saved_photo.processed_image.path).to be_nil result = Workers::ProcessPhoto.new.perform(@saved_photo.id) @saved_photo.reload - @saved_photo.processed_image.path.should_not be_nil - result.should be true + expect(@saved_photo.processed_image.path).not_to be_nil + expect(result).to be true end context 'when trying to process a photo that has already been processed' do @@ -35,8 +35,8 @@ describe Workers::ProcessPhoto do @saved_photo.reload - @saved_photo.processed_image.path.should == processed_image_path - result.should be false + expect(@saved_photo.processed_image.path).to eq(processed_image_path) + expect(result).to be false end end @@ -50,8 +50,8 @@ describe Workers::ProcessPhoto do it 'does not process the gif' do result = Workers::ProcessPhoto.new.perform(@saved_gif.id) - @saved_gif.reload.processed_image.path.should be_nil - result.should be false + expect(@saved_gif.reload.processed_image.path).to be_nil + expect(result).to be false end end diff --git a/spec/workers/publish_to_hub_spec.rb b/spec/workers/publish_to_hub_spec.rb index 47cb4a9a4ae0f3dd1c841e1cab44667bc0f97d71..d864ae2c9e959152cb0cf962a85aa044e205518e 100644 --- a/spec/workers/publish_to_hub_spec.rb +++ b/spec/workers/publish_to_hub_spec.rb @@ -10,8 +10,8 @@ describe Workers::PublishToHub do url = "http://publiczone.com/" m = double() - m.should_receive(:publish).with(url+'.atom') - Pubsubhubbub.should_receive(:new).with(AppConfig.environment.pubsub_server).and_return(m) + expect(m).to receive(:publish).with(url+'.atom') + expect(Pubsubhubbub).to receive(:new).with(AppConfig.environment.pubsub_server).and_return(m) Workers::PublishToHub.new.perform(url) end end diff --git a/spec/workers/receive_salmon_spec.rb b/spec/workers/receive_salmon_spec.rb index 84e598e33cbaa14cef5aab6860d69cdcb3c2afdf..a57bc6fbcdd51d01fd8e96dda49f57762016685a 100644 --- a/spec/workers/receive_salmon_spec.rb +++ b/spec/workers/receive_salmon_spec.rb @@ -4,7 +4,7 @@ describe Workers::ReceiveEncryptedSalmon do before do @user = alice @xml = '<xml></xml>' - User.stub(:find){ |id| + allow(User).to receive(:find){ |id| if id == @user.id @user else @@ -15,8 +15,8 @@ describe Workers::ReceiveEncryptedSalmon do it 'calls receive_salmon' do zord = double - zord.should_receive(:perform!) - Postzord::Receiver::Private.should_receive(:new).with(@user, hash_including(:salmon_xml => @xml)).and_return(zord) + expect(zord).to receive(:perform!) + expect(Postzord::Receiver::Private).to receive(:new).with(@user, hash_including(:salmon_xml => @xml)).and_return(zord) Workers::ReceiveEncryptedSalmon.new.perform(@user.id, @xml) end diff --git a/spec/workers/receive_spec.rb b/spec/workers/receive_spec.rb index dda95c8906e7ed0b1276ed94135d175ca8241f08..0ee0b0a5341bc6346afa1eacf3144ed40218d537 100644 --- a/spec/workers/receive_spec.rb +++ b/spec/workers/receive_spec.rb @@ -5,7 +5,7 @@ describe Workers::Receive do @user = alice @person = FactoryGirl.create(:person) @xml = '<xml></xml>' - User.stub(:find){ |id| + allow(User).to receive(:find){ |id| if id == @user.id @user else @@ -16,8 +16,8 @@ describe Workers::Receive do it 'calls receive' do zord_double = double() - zord_double.should_receive(:parse_and_receive).with(@xml) - Postzord::Receiver::Private.should_receive(:new).with(@user, anything).and_return(zord_double) + expect(zord_double).to receive(:parse_and_receive).with(@xml) + expect(Postzord::Receiver::Private).to receive(:new).with(@user, anything).and_return(zord_double) Workers::Receive.new.perform(@user.id, @xml, @person.id) end end diff --git a/spec/workers/resend_invitation_spec.rb b/spec/workers/resend_invitation_spec.rb index a0e0afd3327a600eec562837e2ded6a87b6a28c0..002cf78a570468f79f9828f7d384135ece386908 100644 --- a/spec/workers/resend_invitation_spec.rb +++ b/spec/workers/resend_invitation_spec.rb @@ -9,8 +9,8 @@ describe Workers::ResendInvitation do it 'should call .resend on the object' do invite = FactoryGirl.build(:invitation, :service => 'email', :identifier => 'foo@bar.com') - Invitation.stub(:find).and_return(invite) - invite.should_receive(:resend) + allow(Invitation).to receive(:find).and_return(invite) + expect(invite).to receive(:resend) Workers::ResendInvitation.new.perform(invite.id) end end diff --git a/spec/workers/reset_password_spec.rb b/spec/workers/reset_password_spec.rb index eed8697d774baa1b375fad983b68c2774da27327..f0f393f7578d7058682a283ee8db6d645b1a6aee 100644 --- a/spec/workers/reset_password_spec.rb +++ b/spec/workers/reset_password_spec.rb @@ -11,8 +11,8 @@ describe Workers::ResetPassword do it "correctly sets the message parameters" do Workers::ResetPassword.new.perform(alice.id) mail = Devise.mailer.deliveries.last - mail.to.should == [alice.email] - mail.body.should include("change your password") + expect(mail.to).to eq([alice.email]) + expect(mail.body).to include("change your password") end end end