Skip to content

Instantly share code, notes, and snippets.

@tkyowa
Created July 23, 2012 02:17
Show Gist options
  • Save tkyowa/3161692 to your computer and use it in GitHub Desktop.
Save tkyowa/3161692 to your computer and use it in GitHub Desktop.
RSpec codes

NOT DRY

describe "hogehoge"
  context "case A" do
    before do
      @user = User.guest
    end

    # test cases
  end

  context "case B" do
    before do
      @user = User.registered
    end

    # test cases
  end
end

describe "fugafuga"
  context "case A" do
    before do
      @user = User.guest
    end

    # test cases
  end

  context "case B" do
    before do
      @user = User.registered
    end

    # test cases
  end
end

DRY

describe "hogehoge"
  guest_user_context do
    # test cases
  end

  paid_user_context do
    # test cases
  end
end

describe "fugafuga"
  guest_user_context do
    # test cases
  end

  paid_user_context do
    # test cases
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment