Skip to content

Instantly share code, notes, and snippets.

@reinh
Forked from coreyhaines/.rspec
Last active December 15, 2015 00:19

Revisions

  1. reinh revised this gist Mar 15, 2013. 1 changed file with 13 additions and 7 deletions.
    20 changes: 13 additions & 7 deletions coderetreat_spec.rb
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,20 @@

    describe Coderetreat do
    describe ".running_today" do
    it "returns a coderetreat scheduled for today" do
    coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today
    Coderetreat.running_today.all.should =~ [coderetreat]
    subject { Coderetreat.running_today }

    def coderetreat_on(date)
    Coderetreat.create! city: "Chicago", scheduled_on: date
    end

    it "does not return a coderetreat not scheduled for today" do
    coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today.advance(:days => -1)
    Coderetreat.running_today.should be_empty

    context 'with a coderetreat scheduled for today' do
    let(:coderetreat) { coderetreat_on Date.today }
    it { should include coderetreat }
    end

    context 'with a coderetreat not scheduled for today' do
    let(:coderetreat) { coderetreat_on Date.today.advance(:days => -1) }
    it { should_not include coderetreat }
    end
    end
    end
  2. @coreyhaines coreyhaines revised this gist Dec 3, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion active_record_spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    require 'active_record'
    require 'database_cleaner'

    connection_info = YAML.load(File.open("config/database.yml"))["test"]
    connection_info = YAML.load_file("config/database.yml")["test"]
    ActiveRecord::Base.establish_connection(connection_info)

    RSpec.configure do |config|
  3. @coreyhaines coreyhaines revised this gist Aug 5, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,7 @@
    #Replace this line
    config.use_transactional_fixtures = true

    #With these
    require 'database_cleaner'
    #With this
    require 'active_record_spec_helper'

    #TADA
  4. @coreyhaines coreyhaines revised this gist Aug 4, 2012. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #Some databases get upset if you try to start a new transaction while a transaction is already in play, so running the whole spec suite chokes when rspec is trying to start a transaction. You need to update your spec_helper to rely on active_record_spec_helper to do this for you.

    #Replace this line
    config.use_transactional_fixtures = true

    #With these
    require 'database_cleaner'
    require 'active_record_spec_helper'

    #TADA
  5. @coreyhaines coreyhaines revised this gist Aug 4, 2012. No changes.
  6. @coreyhaines coreyhaines revised this gist Mar 18, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions .rspec
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    --colour
    -I app
  7. @coreyhaines coreyhaines revised this gist Mar 18, 2012. 2 changed files with 21 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions coderetreat.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    class Coderetreat < ActiveRecord::Base
    def self.running_today
    where(scheduled_on: Date.today)
    end
    end
    16 changes: 16 additions & 0 deletions coderetreat_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    require 'active_record_spec_helper'
    require 'models/coderetreat'

    describe Coderetreat do
    describe ".running_today" do
    it "returns a coderetreat scheduled for today" do
    coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today
    Coderetreat.running_today.all.should =~ [coderetreat]
    end

    it "does not return a coderetreat not scheduled for today" do
    coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today.advance(:days => -1)
    Coderetreat.running_today.should be_empty
    end
    end
    end
  8. @coreyhaines coreyhaines created this gist Mar 18, 2012.
    18 changes: 18 additions & 0 deletions active_record_spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    require 'active_record'
    require 'database_cleaner'

    connection_info = YAML.load(File.open("config/database.yml"))["test"]
    ActiveRecord::Base.establish_connection(connection_info)

    RSpec.configure do |config|
    config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
    end
    config.before(:each) do
    DatabaseCleaner.start
    end
    config.after(:each) do
    DatabaseCleaner.clean
    end
    end