First tests in rspec, with factory_girl

This commit is contained in:
Henne Vogelsang 2014-04-09 01:32:47 +02:00
parent accd7d1a58
commit e3fd0c195a
11 changed files with 131 additions and 19 deletions

View file

@ -0,0 +1,10 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :call_for_papers do
start_date Date.today - 1
end_date Date.today + 7
hard_deadline Date.today + 8
description "We call for papers"
end
end

View file

@ -0,0 +1,13 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :conference do
title "The dog and pony show"
short_title "dps14"
social_tag "dps14"
timezone "Amsterdam"
contact_email "admin@example.com"
start_date Date.today
end_date Date.tomorrow
end
end

10
spec/factories/users.rb Normal file
View file

@ -0,0 +1,10 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :user do
email 'example@example.com'
password 'changeme'
password_confirmation 'changeme'
confirmed_at Time.now
end
end

View file

@ -0,0 +1,60 @@
require 'spec_helper'
describe Conference do
before do
@conference = create(:conference)
end
describe "#registration_open?" do
context "closed registration" do
it "#registration_open? is false" do
expect(@conference.registration_open?).to be false
end
end
context "open registration" do
before do
@conference.registration_start_date = Date.today - 1
@conference.registration_end_date = Date.today + 7
end
it "#registration_open? is true" do
expect(@conference.registration_open?).to be true
end
end
end
describe "#cfp_open?" do
context "closed cfp" do
it "#cfp_open? is false" do
expect(@conference.cfp_open?).to be false
end
end
context "open cfp" do
before do
@cfp = create(:call_for_papers)
@conference.call_for_papers = @cfp
end
it "#registration_open? is true" do
expect(@conference.cfp_open?).to be true
end
end
end
describe "#user_registered?" do
before do
@user = create(:user)
end
context "user not registered" do
it "#user_registered? is false" do
expect(@conference.user_registered? @user).to be false
end
end
context "user registered" do
pending "isn't tested yet"
end
end
end

View file

@ -34,4 +34,12 @@ RSpec.configure do |config|
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
# Include factory_girls syntax
config.include FactoryGirl::Syntax::Methods
# As we start from scratch in April 2014, let's forbid the old :should syntax
config.expect_with :rspec do |c|
c.syntax = :expect
end
end

View file

@ -0,0 +1,7 @@
RSpec.configure do |config|
config.before(:suite) do
FactoryGirl.lint
end
end

7
spec/support/seeds.rb Normal file
View file

@ -0,0 +1,7 @@
RSpec.configure do |config|
config.before(:suite) do
load "#{Rails.root}/db/seeds.rb"
end
end