kanedayo / api_ver_test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#APIのバージョニング練習環境

rspecのインストール

#Gemfile
gourp :development, :test do
  gem 'rspec-rails'
end

$ bundle install
$ rails g rspec:install

$ rake db:test:prepare

実行

$ rake db:migrate RAILS_ENV=test

FactoryGirl:設定ファイル例

# spec/factories/data.rb
FactoryGirl.define do
  factory :datum do
    title "AAA"
    category_id 1
  end
end

RSpec:テストの記述例

# spec/models/datum_spec.rb
RSpec.describe Datum, :type => :model do
  it "AA" do # example(AA)
    expect( xxx ).to be_valid
  end

  describe "BB" do # グルーピング可能
    it "BB-00" do # example(BB-00)
      expect( xxx ).not_to be_valid
    end
  end
end

Guard関連

# Gemfile
gem 'terminal-notifier-guard'
gem 'guard-rspec'
$ guard init rspec
$ bundle exec guard

###参考URL: RailsでAPI作成とAPIのテストのまとめ

FactoryGirlの使い方

FactoryGirl/GETTING_STARTED

About


Languages

Language:Ruby 77.8%Language:HTML 16.6%Language:CSS 3.8%Language:JavaScript 1.3%Language:CoffeeScript 0.4%