prepare for RSpec 3.0

This commit is contained in:
wvengen 2014-08-19 11:39:33 +02:00
parent 61a1efdfcf
commit 21838e9c84
7 changed files with 41 additions and 40 deletions

View file

@ -92,8 +92,7 @@ group :test do
gem 'database_cleaner' gem 'database_cleaner'
gem 'connection_pool' gem 'connection_pool'
# need to include rspec components before i18n-spec or rake fails in test environment # need to include rspec components before i18n-spec or rake fails in test environment
gem 'rspec-core', '= 2.14.8' # version until we're ready for rspec 3.0 gem 'rspec-core', '~> 2.99' # almost ready for RSpec 3
gem 'rspec-expectations'
gem 'rspec-rerun' gem 'rspec-rerun'
gem 'i18n-spec' gem 'i18n-spec'
# code coverage # code coverage

View file

@ -172,7 +172,7 @@ GEM
activesupport (>= 3.2, < 5) activesupport (>= 3.2, < 5)
hike (1.2.3) hike (1.2.3)
i18n (0.6.11) i18n (0.6.11)
i18n-spec (0.5.1) i18n-spec (0.5.2)
iso iso
inherited_resources (1.5.0) inherited_resources (1.5.0)
has_scope (~> 0.6.0.rc) has_scope (~> 0.6.0.rc)
@ -282,22 +282,25 @@ GEM
mime-types (>= 1.16, < 3.0) mime-types (>= 1.16, < 3.0)
netrc (~> 0.7) netrc (~> 0.7)
rinku (1.7.3) rinku (1.7.3)
rspec (2.14.1) rspec (2.99.0)
rspec-core (~> 2.14.0) rspec-core (~> 2.99.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.99.0)
rspec-core (2.14.8) rspec-collection_matchers (1.0.0)
rspec-expectations (2.14.5) rspec-expectations (>= 2.99.0.beta1)
rspec-core (2.99.1)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6) rspec-mocks (2.99.2)
rspec-rails (2.14.2) rspec-rails (2.99.0)
actionpack (>= 3.0) actionpack (>= 3.0)
activemodel (>= 3.0) activemodel (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
rspec-core (~> 2.14.0) rspec-collection_matchers
rspec-expectations (~> 2.14.0) rspec-core (~> 2.99.0)
rspec-mocks (~> 2.14.0) rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-rerun (0.2.0) rspec-rerun (0.2.0)
rspec (>= 2.11.0, < 3) rspec (>= 2.11.0, < 3)
ruby-prof (0.15.1) ruby-prof (0.15.1)
@ -441,8 +444,7 @@ DEPENDENCIES
rails-settings-cached rails-settings-cached
ransack ransack
resque resque
rspec-core (= 2.14.8) rspec-core (~> 2.99)
rspec-expectations
rspec-rails rspec-rails
rspec-rerun rspec-rerun
ruby-prof ruby-prof

View file

@ -57,7 +57,7 @@ describe 'settling an order', :type => :feature do
page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.accept
end end
expect(page).to_not have_selector("#order_article_#{oa.id}") expect(page).to_not have_selector("#order_article_#{oa.id}")
expect(OrderArticle.exists?(oa.id)).to be_true expect(OrderArticle.exists?(oa.id)).to be true
oa.reload oa.reload
expect(oa.quantity).to eq(4) expect(oa.quantity).to eq(4)
expect(oa.tolerance).to eq(0) expect(oa.tolerance).to eq(0)
@ -74,7 +74,7 @@ describe 'settling an order', :type => :feature do
page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.accept
end end
expect(page).to_not have_selector("#order_article_#{oa.id}") expect(page).to_not have_selector("#order_article_#{oa.id}")
expect(OrderArticle.exists?(oa.id)).to be_false expect(OrderArticle.exists?(oa.id)).to be false
end end
it 'keeps ordered quantities when GroupOrderArticle is deleted from resulting order' do it 'keeps ordered quantities when GroupOrderArticle is deleted from resulting order' do
@ -84,8 +84,8 @@ describe 'settling an order', :type => :feature do
click_link I18n.t('ui.delete') click_link I18n.t('ui.delete')
end end
expect(page).to_not have_selector("#group_order_article_#{goa1.id}") expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
expect(OrderArticle.exists?(oa.id)).to be_true expect(OrderArticle.exists?(oa.id)).to be true
expect(GroupOrderArticle.exists?(goa1.id)).to be_true expect(GroupOrderArticle.exists?(goa1.id)).to be true
goa1.reload goa1.reload
expect(goa1.result).to eq(0) expect(goa1.result).to eq(0)
expect(goa1.quantity).to eq(3) expect(goa1.quantity).to eq(3)
@ -100,8 +100,8 @@ describe 'settling an order', :type => :feature do
click_link I18n.t('ui.delete') click_link I18n.t('ui.delete')
end end
expect(page).to_not have_selector("#group_order_article_#{goa1.id}") expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
expect(OrderArticle.exists?(oa.id)).to be_true expect(OrderArticle.exists?(oa.id)).to be true
expect(GroupOrderArticle.exists?(goa1.id)).to be_false expect(GroupOrderArticle.exists?(goa1.id)).to be false
end end
it 'keeps product when amount is set to zero' do it 'keeps product when amount is set to zero' do
@ -116,7 +116,7 @@ describe 'settling an order', :type => :feature do
# make sure it still works after reloading # make sure it still works after reloading
visit new_finance_order_path(order_id: order.id) visit new_finance_order_path(order_id: order.id)
expect(page).to have_selector("#order_article_#{oa.id}") expect(page).to have_selector("#order_article_#{oa.id}")
expect(OrderArticle.exists?(oa.id)).to be_true expect(OrderArticle.exists?(oa.id)).to be true
oa.reload oa.reload
expect(oa.units_to_order).to eq(0) expect(oa.units_to_order).to eq(0)
end end

View file

@ -30,9 +30,9 @@ describe Article do
end end
it 'knows when it is deleted' do it 'knows when it is deleted' do
expect(supplier.deleted?).to be_false expect(supplier.deleted?).to be false
supplier.mark_as_deleted supplier.mark_as_deleted
expect(supplier.deleted?).to be_true expect(supplier.deleted?).to be true
end end
it 'keeps a price history' do it 'keeps a price history' do
@ -70,7 +70,7 @@ describe Article do
it 'can find updates' do it 'can find updates' do
changed = article.shared_article_changed? changed = article.shared_article_changed?
expect(changed).to_not be_false expect(changed).to_not be_falsey
expect(changed.length).to be > 1 expect(changed.length).to be > 1
end end
@ -81,12 +81,12 @@ describe Article do
article.update_attributes updated_article.attributes.reject{|k,v| k=='id' or k=='type'} article.update_attributes updated_article.attributes.reject{|k,v| k=='id' or k=='type'}
expect(article.name).to eq(shared_article.name) expect(article.name).to eq(shared_article.name)
# now synchronising shouldn't change anything anymore # now synchronising shouldn't change anything anymore
expect(article.shared_article_changed?).to be_false expect(article.shared_article_changed?).to be_falsey
end end
it 'does not need to synchronise an imported article' do it 'does not need to synchronise an imported article' do
article = SharedArticle.find(shared_article.id).build_new_article(supplier) article = SharedArticle.find(shared_article.id).build_new_article(supplier)
expect(article.shared_article_changed?).to be_false expect(article.shared_article_changed?).to be_falsey
end end
it 'adapts to foodcoop units when synchronising' do it 'adapts to foodcoop units when synchronising' do

View file

@ -38,7 +38,7 @@ describe GroupOrderArticle do
it 'can unorder a product' do it 'can unorder a product' do
goa.update_quantities(rand(1..99), rand(0..99)) goa.update_quantities(rand(1..99), rand(0..99))
goa.update_quantities(0, 0) goa.update_quantities(0, 0)
expect(GroupOrderArticle.exists?(goa.id)).to be_false expect(GroupOrderArticle.exists?(goa.id)).to be false
end end
end end

View file

@ -16,18 +16,18 @@ describe User do
describe 'does not have the role' do describe 'does not have the role' do
let(:user) { create :user } let(:user) { create :user }
it 'admin' do expect(user.role_admin?).to be_false end it 'admin' do expect(user.role_admin?).to be_falsey end
it 'finance' do expect(user.role_finance?).to be_false end it 'finance' do expect(user.role_finance?).to be_falsey end
it 'article_meta' do expect(user.role_article_meta?).to be_false end it 'article_meta' do expect(user.role_article_meta?).to be_falsey end
it 'suppliers' do expect(user.role_suppliers?).to be_false end it 'suppliers' do expect(user.role_suppliers?).to be_falsey end
it 'orders' do expect(user.role_orders?).to be_false end it 'orders' do expect(user.role_orders?).to be_falsey end
end end
describe do describe do
let(:user) { create :user, password: 'blahblah' } let(:user) { create :user, password: 'blahblah' }
it 'can authenticate with correct password' do it 'can authenticate with correct password' do
expect(User.authenticate(user.nick, 'blahblah')).to be_true expect(User.authenticate(user.nick, 'blahblah')).to be_truthy
end end
it 'can not authenticate with incorrect password' do it 'can not authenticate with incorrect password' do
expect(User.authenticate(user.nick, 'foobar')).to be_nil expect(User.authenticate(user.nick, 'foobar')).to be_nil
@ -51,19 +51,19 @@ describe User do
end end
it 'can authenticate using email address' do it 'can authenticate using email address' do
expect(User.authenticate(user.email, 'blahblah')).to be_true expect(User.authenticate(user.email, 'blahblah')).to be_truthy
end end
it 'can authenticate when there is no nick' do it 'can authenticate when there is no nick' do
user.nick = nil user.nick = nil
expect(user).to be_valid expect(user).to be_valid
expect(User.authenticate(user.email, 'blahblah')).to be_true expect(User.authenticate(user.email, 'blahblah')).to be_truthy
end end
end end
describe 'admin' do describe 'admin' do
let(:user) { create :admin } let(:user) { create :admin }
it 'default admin role' do expect(user.role_admin?).to be_true end it 'default admin role' do expect(user.role_admin?).to be_truthy end
end end
end end

View file

@ -28,10 +28,10 @@ RSpec.configure do |config|
#config.use_transactional_fixtures = true #config.use_transactional_fixtures = true
# We use capybara with selenium, and need database_cleaner # We use capybara with selenium, and need database_cleaner
config.before(:each) do config.before(:each) do
DatabaseCleaner.strategy = (example.metadata[:js] ? :truncation : :transaction) DatabaseCleaner.strategy = (RSpec.current_example.metadata[:js] ? :truncation : :transaction)
DatabaseCleaner.start DatabaseCleaner.start
# maximise window so that buttons can be found on popups # maximise window so that buttons can be found on popups
example.metadata[:js] and page.driver.browser.manage.window.maximize RSpec.current_example.metadata[:js] and page.driver.browser.manage.window.maximize
end end
config.after(:each) do config.after(:each) do
DatabaseCleaner.clean DatabaseCleaner.clean