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
article2 = FactoryGirl.build :article, supplier: supplier, name: article.name
article2.should_not be_valid
expect(article2).to be_invalid
end
it 'computes the gross price correctly' do
article.deposit = 0
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.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
it 'gross price >= net price' do
article.gross_price.should >= article.price
expect(article.gross_price).to be >= article.price
end
it 'fc-price > gross price' do
article.fc_price.should > article.gross_price
expect(article.fc_price).to be > article.gross_price
end
it 'knows when it is deleted' do
supplier.deleted?.should be_false
expect(supplier.deleted?).to be_false
supplier.mark_as_deleted
supplier.deleted?.should be_true
expect(supplier.deleted?).to be_true
end
it 'keeps a price history' do
article.article_prices.count.should == 1
expect(article.article_prices.count).to eq(1)
oldprice = article.price
article.price += 1
article.save!
article.article_prices.count.should == 2
article.article_prices[0].price.should == article.price
article.article_prices[-1].price.should == oldprice
expect(article.article_prices.count).to eq(2)
expect(article.article_prices[0].price).to eq(article.price)
expect(article.article_prices[-1].price).to eq(oldprice)
end
end

View File

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

View File

@ -3,45 +3,45 @@ require 'spec_helper'
describe Order do
it 'needs a supplier' do
FactoryGirl.build(:order).should_not be_valid
expect(FactoryGirl.build(:order)).to be_invalid
end
it 'needs order articles' do
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
it 'can be created' do
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
describe 'with articles' do
let(:supplier) { FactoryGirl.create :supplier, article_count: true }
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 not finished by default' do order.finished?.should be_false end
it 'is not closed by default' do order.closed?.should be_false end
it 'is open by default' do expect(order).to be_open end
it 'is not finished by default' do expect(order).to_not be_finished end
it 'is not closed by default' do expect(order).to_not be_closed end
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
it 'can be finished' do
# TODO randomise user
order.finish!(User.first)
order.open?.should be_false
order.finished?.should be_true
order.closed?.should be_false
expect(order).to_not be_open
expect(order).to be_finished
expect(order).to_not be_closed
end
it 'can be closed' do
# TODO randomise user
order.finish!(User.first)
order.close!(User.first)
order.open?.should be_false
order.closed?.should be_true
expect(order).to_not be_open
expect(order).to be_closed
end
end

View File

@ -5,12 +5,12 @@ describe Supplier do
it 'has a unique name' do
supplier2 = FactoryGirl.build :supplier, name: supplier.name
supplier2.should_not be_valid
expect(supplier2).to be_invalid
end
it 'has valid articles' do
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

View File

@ -6,54 +6,54 @@ describe User do
user = FactoryGirl.create :user,
nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar',
email: 'johnnydoe@foodcoop.test', phone: '+1234567890'
user.nick.should == 'johnnydoe'
user.first_name.should == 'Johnny'
user.last_name.should == 'DoeBar'
user.name.should == 'Johnny DoeBar'
user.email.should == 'johnnydoe@foodcoop.test'
user.phone.should == '+1234567890'
expect(user.nick).to eq('johnnydoe')
expect(user.first_name).to eq('Johnny')
expect(user.last_name).to eq('DoeBar')
expect(user.name).to eq('Johnny DoeBar')
expect(user.email).to eq('johnnydoe@foodcoop.test')
expect(user.phone).to eq('+1234567890')
end
describe 'does not have the role' do
let(:user) { FactoryGirl.create :user }
it 'admin' do user.role_admin?.should be_false end
it 'finance' do user.role_finance?.should be_false end
it 'article_meta' do user.role_article_meta?.should be_false end
it 'suppliers' do user.role_suppliers?.should be_false end
it 'orders' do user.role_orders?.should be_false end
it 'admin' do expect(user.role_admin?).to be_false end
it 'finance' do expect(user.role_finance?).to be_false end
it 'article_meta' do expect(user.role_article_meta?).to be_false end
it 'suppliers' do expect(user.role_suppliers?).to be_false end
it 'orders' do expect(user.role_orders?).to be_false end
end
describe do
let(:user) { FactoryGirl.create :user, password: 'blahblah' }
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
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
it 'can not set a password without matching confirmation' do
user.password = 'abcdefghij'
user.password_confirmation = 'foobarxyz'
user.should_not be_valid
expect(user).to be_invalid
end
it 'can set a password with matching confirmation' do
user.password = 'abcdefghij'
user.password_confirmation = 'abcdefghij'
user.should be_valid
expect(user).to be_valid
end
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
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
describe 'admin' do
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