読者です 読者をやめる 読者になる 読者になる

ボクココ

サービス開発を成功させるまでの歩み

Rails x MongoDB x RSpec にしたときのScaffoldで作られるファイルたち

Rails MongoDB


$ rails g scaffold article subject:string body:text

invoke mongo_mapper
create app/models/article.rb
invoke rspec
create spec/models/article_spec.rb
invoke factory_girl
create spec/factories/articles.rb
route resources :articles
invoke scaffold_controller
create app/controllers/articles_controller.rb
invoke erb
create app/views/articles
create app/views/articles/index.html.erb
create app/views/articles/edit.html.erb
create app/views/articles/show.html.erb
create app/views/articles/new.html.erb
create app/views/articles/_form.html.erb
invoke rspec
create spec/controllers/articles_controller_spec.rb
create spec/views/articles/edit.html.erb_spec.rb
create spec/views/articles/index.html.erb_spec.rb
create spec/views/articles/new.html.erb_spec.rb
create spec/views/articles/show.html.erb_spec.rb
invoke helper
create spec/helpers/articles_helper_spec.rb
create spec/routing/articles_routing_spec.rb
invoke helper
create app/helpers/articles_helper.rb
invoke rspec
invoke assets
invoke coffee
create app/assets/javascripts/articles.js.coffee
invoke scss
create app/assets/stylesheets/articles.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss

ここで、specの煩わしいディレクトリは消すのが慣習っぽい。

$ rm -rf spec/views
$ rm -rf spec/helpers

RSpecの書き方は慣れていかないと。。後で読む↓
http://jp.rubyist.net/magazine/?0021-Rspec
http://d.hatena.ne.jp/keisukefukuda/20080124/p1



Scaffoldで土台作ってテスト実行したら、失敗してた。軽く修正。

assigns(:articles).should eq([article])

assigns(:articles)[-1].should eq(article)

response.should redirect_to(Article.last)

response.should redirect_to(assigns(:article))