title: Ruby on Rails 4 and RSPEC
body: <p>I am trying to get to grips with Rails and Rspec for testing using Capybara. I’m currently trying to test for uniqueness of a Profile Name for User. However from reading around fixtures should not be used with Rspec. How do I go about adding some base data for me to test against.</p>
  
  <p>Gemfile</p>
  
  <pre><code>source 'https://rubygems.org'
  
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '4.0.3'
  
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
  
  # Use SCSS for stylesheets
  gem 'sass-rails', '~&gt; 4.0.0'
  
  # Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '&gt;= 1.3.0'
  
  # Use CoffeeScript for .js.coffee assets and views
  gem 'coffee-rails', '~&gt; 4.0.0'
  
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', platforms: :ruby
  
  # Use jquery as the JavaScript library
  gem 'jquery-rails'
  
  # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
  gem 'turbolinks'
  
  # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
  gem 'jbuilder', '~&gt; 1.2'
  
  gem 'devise', '~&gt; 3.2.3'
  gem 'simple_form', '~&gt; 3.0.1'
  
  group :doc do
    # bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', require: false
  end
  
  group :development do
    gem 'awesome_print'
  end
  
  group :development, :test do
    gem 'rspec-rails', '~&gt; 2.0'
  end
  
  group :test do
   gem 'capybara', '~&gt; 2.0'
  end
  
  # Use ActiveModel has_secure_password
  # gem 'bcrypt-ruby', '~&gt; 3.1.2'
  
  # Use unicorn as the app server
  # gem 'unicorn'
  
  # Use Capistrano for deployment
  # gem 'capistrano', group: :development
  
  # Use debugger
  # gem 'debugger', group: [:development, :test]
  </code></pre>
  
  <p>Create_spec.rb</p>
  
  <pre><code>require 'spec_helper'
  
  describe "Creating a new user" do
    def create_user(options={})
      options[:first_name] ||= "Adam"
      options[:last_name] ||= "Sackfield"
      options[:profile_name] ||= "Sacki"
      options[:email] ||= "email@email.com"
      options[:password] ||= "password"
  
      visit "/users/sign_up"
      expect(page).to have_content "Sign up"
  
      fill_in "First name", with: options[:first_name]
      fill_in "Last name", with: options[:last_name]
      fill_in "Profile name", with: options[:profile_name]
      fill_in "Email", with: options[:email]
      fill_in "Password", with: options[:password]
      fill_in "Password confirmation", with: options[:password]
  
      click_button "Sign up"
    end
  
    it "a user can register" do
     create_user
     expect(page).to have_content "You have signed up"
    end
  
    it "a user must enter a first name" do
      create_user first_name: ""
      expect(page).to_not have_content "You have signed up"
    end
  
    it "a user must enter a last name" do
      create_user last_name: ""
      expect(page).to_not have_content "You have signed up"
    end
  end
  </code></pre>
  
  <p>Thanks</p>