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
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