use expect instead of should in specs

This commit is contained in:
wvengen 2013-07-24 22:46:25 +02:00
parent 0be3955cd7
commit d602b7cd0d
6 changed files with 60 additions and 60 deletions

View File

@ -6,39 +6,39 @@ describe Article do
it 'has a unique name' do it 'has a unique name' do
article2 = FactoryGirl.build :article, supplier: supplier, name: article.name article2 = FactoryGirl.build :article, supplier: supplier, name: article.name
article2.should_not be_valid expect(article2).to be_invalid
end end
it 'computes the gross price correctly' do it 'computes the gross price correctly' do
article.deposit = 0 article.deposit = 0
article.tax = 12 article.tax = 12
article.gross_price.should == (article.price * 1.12).round(2) expect(article.gross_price).to eq((article.price * 1.12).round(2))
article.deposit = 1.20 article.deposit = 1.20
article.gross_price.should == ((article.price + 1.20) * 1.12).round(2) expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2))
end end
it 'gross price >= net price' do it 'gross price >= net price' do
article.gross_price.should >= article.price expect(article.gross_price).to be >= article.price
end end
it 'fc-price > gross price' do it 'fc-price > gross price' do
article.fc_price.should > article.gross_price expect(article.fc_price).to be > article.gross_price
end end
it 'knows when it is deleted' do it 'knows when it is deleted' do
supplier.deleted?.should be_false expect(supplier.deleted?).to be_false
supplier.mark_as_deleted supplier.mark_as_deleted
supplier.deleted?.should be_true expect(supplier.deleted?).to be_true
end end
it 'keeps a price history' do it 'keeps a price history' do
article.article_prices.count.should == 1 expect(article.article_prices.count).to eq(1)
oldprice = article.price oldprice = article.price
article.price += 1 article.price += 1
article.save! article.save!
article.article_prices.count.should == 2 expect(article.article_prices.count).to eq(2)
article.article_prices[0].price.should == article.price expect(article.article_prices[0].price).to eq(article.price)
article.article_prices[-1].price.should == oldprice expect(article.article_prices[-1].price).to eq(oldprice)
end end
end end

View File

@ -7,11 +7,11 @@ describe GroupOrderArticle do
let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup } let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup }
let(:goa) { FactoryGirl.create :group_order_article, group_order: go, order_article: order.order_articles.first } let(:goa) { FactoryGirl.create :group_order_article, group_order: go, order_article: order.order_articles.first }
it 'has zero quantity by default' do goa.quantity.should == 0 end it 'has zero quantity by default' do expect(goa.quantity).to eq(0) end
it 'has zero tolerance by default' do goa.tolerance.should == 0 end it 'has zero tolerance by default' do expect(goa.tolerance).to eq(0) end
it 'has zero result by default' do goa.result.should == 0 end it 'has zero result by default' do expect(goa.result).to eq(0) end
it 'is not ordered by default' do GroupOrderArticle.ordered.where(:id => goa.id).exists?.should be_false end it 'is not ordered by default' do expect(GroupOrderArticle.ordered.where(:id => goa.id).exists?).to be_false end
it 'has zero total price by default' do goa.total_price.should == 0 end it 'has zero total price by default' do expect(goa.total_price).to eq(0) end
describe do describe do
let(:article) { FactoryGirl.create :article, supplier: supplier, unit_quantity: 1 } let(:article) { FactoryGirl.create :article, supplier: supplier, unit_quantity: 1 }
@ -19,28 +19,28 @@ describe GroupOrderArticle do
it 'can be ordered by piece' do it 'can be ordered by piece' do
goa.update_quantities(1, 0) goa.update_quantities(1, 0)
goa.quantity.should == 1 expect(goa.quantity).to eq(1)
goa.tolerance == 0 expect(goa.tolerance).to eq(0)
end end
it 'can be ordered in larger amounts' do it 'can be ordered in larger amounts' do
quantity, tolerance = rand(13..100), rand(0..100) quantity, tolerance = rand(13..100), rand(0..100)
goa.update_quantities(quantity, tolerance) goa.update_quantities(quantity, tolerance)
goa.quantity.should == quantity expect(goa.quantity).to eq(quantity)
goa.tolerance.should == tolerance expect(goa.tolerance).to eq(tolerance)
end end
it 'has a proper total price' do it 'has a proper total price' do
quantity = rand(1..100) quantity = rand(1..100)
goa.update_quantities(quantity, 0) goa.update_quantities(quantity, 0)
goa.total_price.should == quantity * goa.order_article.price.fc_price expect(goa.total_price).to eq(quantity * goa.order_article.price.fc_price)
end end
it 'can unorder a product' do it 'can unorder a product' do
goa.update_quantities(rand(1..100), rand(0..100)) goa.update_quantities(rand(1..100), rand(0..100))
goa.update_quantities(0, 0) goa.update_quantities(0, 0)
goa.quantity.should == 0 expect(goa.quantity).to eq(0)
goa.tolerance.should == 0 expect(goa.tolerance).to eq(0)
end end
it 'keeps track of article quantities' do it 'keeps track of article quantities' do
@ -53,8 +53,8 @@ describe GroupOrderArticle do
startt.nil? and startt = tolerance startt.nil? and startt = tolerance
end end
goaq = goa.group_order_article_quantities.last goaq = goa.group_order_article_quantities.last
goaq.quantity.should == startq expect(goaq.quantity).to eq(startq)
goaq.tolerance.should == startt expect(goaq.tolerance).to eq(startt)
end end
end end

View File

@ -6,18 +6,18 @@ describe GroupOrder do
let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload } let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload }
it 'needs an order' do it 'needs an order' do
FactoryGirl.build(:group_order, ordergroup: user.ordergroup).should_not be_valid expect(FactoryGirl.build(:group_order, ordergroup: user.ordergroup)).to be_invalid
end end
it 'needs an ordergroup' do it 'needs an ordergroup' do
FactoryGirl.build(:group_order, order: order).should_not be_valid expect(FactoryGirl.build(:group_order, order: order)).to be_invalid
end end
describe do describe do
let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup } let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup }
it 'has zero price initially' do it 'has zero price initially' do
go.price.should == 0 expect(go.price).to eq(0)
end end
end end

View File

@ -3,45 +3,45 @@ require 'spec_helper'
describe Order do describe Order do
it 'needs a supplier' do it 'needs a supplier' do
FactoryGirl.build(:order).should_not be_valid expect(FactoryGirl.build(:order)).to be_invalid
end end
it 'needs order articles' do it 'needs order articles' do
supplier = FactoryGirl.create :supplier, article_count: 0 supplier = FactoryGirl.create :supplier, article_count: 0
FactoryGirl.build(:order, supplier: supplier).should_not be_valid expect(FactoryGirl.build(:order, supplier: supplier)).to be_invalid
end end
it 'can be created' do it 'can be created' do
supplier = FactoryGirl.create :supplier, article_count: 1 supplier = FactoryGirl.create :supplier, article_count: 1
FactoryGirl.build(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).should be_valid expect(FactoryGirl.build(:order, supplier: supplier, article_ids: supplier.articles.map(&:id))).to be_valid
end end
describe 'with articles' do describe 'with articles' do
let(:supplier) { FactoryGirl.create :supplier, article_count: true } let(:supplier) { FactoryGirl.create :supplier, article_count: true }
let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload } let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload }
it 'is open by default' do order.open?.should be_true end it 'is open by default' do expect(order).to be_open end
it 'is not finished by default' do order.finished?.should be_false end it 'is not finished by default' do expect(order).to_not be_finished end
it 'is not closed by default' do order.closed?.should be_false end it 'is not closed by default' do expect(order).to_not be_closed end
it 'has valid order articles' do it 'has valid order articles' do
order.order_articles.all.each {|oa| oa.should be_valid } order.order_articles.all.each {|oa| expect(oa).to be_valid }
end end
it 'can be finished' do it 'can be finished' do
# TODO randomise user # TODO randomise user
order.finish!(User.first) order.finish!(User.first)
order.open?.should be_false expect(order).to_not be_open
order.finished?.should be_true expect(order).to be_finished
order.closed?.should be_false expect(order).to_not be_closed
end end
it 'can be closed' do it 'can be closed' do
# TODO randomise user # TODO randomise user
order.finish!(User.first) order.finish!(User.first)
order.close!(User.first) order.close!(User.first)
order.open?.should be_false expect(order).to_not be_open
order.closed?.should be_true expect(order).to be_closed
end end
end end

View File

@ -5,12 +5,12 @@ describe Supplier do
it 'has a unique name' do it 'has a unique name' do
supplier2 = FactoryGirl.build :supplier, name: supplier.name supplier2 = FactoryGirl.build :supplier, name: supplier.name
supplier2.should_not be_valid expect(supplier2).to be_invalid
end end
it 'has valid articles' do it 'has valid articles' do
supplier = FactoryGirl.create :supplier, article_count: true supplier = FactoryGirl.create :supplier, article_count: true
supplier.articles.all.each {|a| a.should be_valid } supplier.articles.all.each {|a| expect(a).to be_valid }
end end
end end

View File

@ -6,54 +6,54 @@ describe User do
user = FactoryGirl.create :user, user = FactoryGirl.create :user,
nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar', nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar',
email: 'johnnydoe@foodcoop.test', phone: '+1234567890' email: 'johnnydoe@foodcoop.test', phone: '+1234567890'
user.nick.should == 'johnnydoe' expect(user.nick).to eq('johnnydoe')
user.first_name.should == 'Johnny' expect(user.first_name).to eq('Johnny')
user.last_name.should == 'DoeBar' expect(user.last_name).to eq('DoeBar')
user.name.should == 'Johnny DoeBar' expect(user.name).to eq('Johnny DoeBar')
user.email.should == 'johnnydoe@foodcoop.test' expect(user.email).to eq('johnnydoe@foodcoop.test')
user.phone.should == '+1234567890' expect(user.phone).to eq('+1234567890')
end end
describe 'does not have the role' do describe 'does not have the role' do
let(:user) { FactoryGirl.create :user } let(:user) { FactoryGirl.create :user }
it 'admin' do user.role_admin?.should be_false end it 'admin' do expect(user.role_admin?).to be_false end
it 'finance' do user.role_finance?.should be_false end it 'finance' do expect(user.role_finance?).to be_false end
it 'article_meta' do user.role_article_meta?.should be_false end it 'article_meta' do expect(user.role_article_meta?).to be_false end
it 'suppliers' do user.role_suppliers?.should be_false end it 'suppliers' do expect(user.role_suppliers?).to be_false end
it 'orders' do user.role_orders?.should be_false end it 'orders' do expect(user.role_orders?).to be_false end
end end
describe do describe do
let(:user) { FactoryGirl.create :user, password: 'blahblah' } let(:user) { FactoryGirl.create :user, password: 'blahblah' }
it 'can authenticate with correct password' do it 'can authenticate with correct password' do
User.authenticate(user.nick, 'blahblah').should be_true expect(User.authenticate(user.nick, 'blahblah')).to be_true
end end
it 'can not authenticate with incorrect password' do it 'can not authenticate with incorrect password' do
User.authenticate(user.nick, 'foobar').should be_nil expect(User.authenticate(user.nick, 'foobar')).to be_nil
end end
it 'can not set a password without matching confirmation' do it 'can not set a password without matching confirmation' do
user.password = 'abcdefghij' user.password = 'abcdefghij'
user.password_confirmation = 'foobarxyz' user.password_confirmation = 'foobarxyz'
user.should_not be_valid expect(user).to be_invalid
end end
it 'can set a password with matching confirmation' do it 'can set a password with matching confirmation' do
user.password = 'abcdefghij' user.password = 'abcdefghij'
user.password_confirmation = 'abcdefghij' user.password_confirmation = 'abcdefghij'
user.should be_valid expect(user).to be_valid
end end
it 'has a unique nick' do it 'has a unique nick' do
FactoryGirl.build(:user, nick: user.nick, email: "x-#{user.email}").should_not be_valid expect(FactoryGirl.build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
end end
it 'has a unique email' do it 'has a unique email' do
FactoryGirl.build(:user, email: "#{user.email}").should_not be_valid expect(FactoryGirl.build(:user, email: "#{user.email}")).to be_invalid
end end
end end
describe 'admin' do describe 'admin' do
let(:user) { FactoryGirl.create :admin } let(:user) { FactoryGirl.create :admin }
it 'default admin role' do user.role_admin?.should be_true end it 'default admin role' do expect(user.role_admin?).to be_true end
end end
end end