Tag: RSpec
describe Array, "when empty" do before do @empty_array = [] end it "should be empty" do @empty_array.should be_empty end it "should size 0" do @empty_array.size.should == 0 end after do @empty_array = nil end end
describe Array, "when empty" do before do @empty_array = [] end it "should be empty" do @empty_array.should be_empty end it "should size 0" do @empty_array.size.should == 0 end after do @empty_array = nil end end
$ rspec array_spec.rb rspec array_spec.rb .. Finished in 0.00312 seconds 2 examples, 0 failures
group :development, :test do gem "rspec-rails", "~>2.14.0" gem "factory_girl_rails", "~>4.2.1" end group :test do gem "faker", "~>1.1.2" gem "capybara", "~>2.1.0" gem "database_cleaner", "~>1.0.1" gem "launchy", "~>2.3.0" gem "selenium-webdriver", "~>2.39.0" end
bundle install --path vendor/bundle
bundle exec rails generate rspec:install create .rspec create spec create spec/spec_helper.rb
config.generators do |g| g.test_framework :rspec, fixtures: true, view_specs: false, helper_specs: false, routing_specs: false, controller_specs: true, request_specs: false g.fixture_replacement :factory_girl, dir: "spec/factories" end
※注意事項)
group :development, :test do gem "rspec-rails" end
group :production, :development, :test do gem "rspec-rails" end
RAILS_ENV=development bundle exec rails g
gem 'rspec-rails'
bundle install --path=vendor/bundle
bundle exec rails g rspec:install create .rspec create spec create spec/spec_helper.rb
bundle exec rake spec | spec以下の全てのspecを実行 |
bundle exec rake spec | spec/modles以下の全てのspecを実行。 |
bundle exec rake SPEC=spec/models/entry_spec.rb | 個別のspecを実行 |
bundle exec rspec spec/models/entry_spec.rb | 個別のspecを実行rakeより速いかも。 |
$ bundle exec rails generate model Blog name:string invoke active_record create db/migrate/20130419052115_create_blogs.rb create app/models/blog.rb invoke rspec create spec/models/blog_spec.rb
class CreateBlogs < ActiveRecord::Migration def change create_table :blogs do |t| t.string :name, :null => false t.timestamps end end end
$ bundle exec rake db:migrate
one: id: 1 name: その1 two: id: 2 name: その2
# -*- coding: utf-8 -*- require 'spec_helper' describe Blog, "#name が設定されていない場合:" do before(:each) do @blog = Blog.new end it "バリデーションに失敗すること" do @blog.should_not be_valid end end
bundle exec rake pec SPEC=spec/models/blog_spec.rb
class Blog < ActiveRecord::Base attr_accessible :name validates :name, presence:true end
bundle exec rails g rspec:controller softwares
describe Simple, :type => :model ,'説明分' do
describe '説明分', :type => :model do