Rspec在Rails 4 beta中没有生成* _spec.rb文件

时间:2013-06-04 01:33:16

标签: ruby-on-rails rspec cucumber rspec-rails ruby-on-rails-4

我已经安装了rspec-rails gem。当我跑rails g model movie showtime_date:date showtime_time:time时,我认为,我应该

invoke  active_record
      create    db/migrate/20130604010556_create_movies.rb
      create    app/models/movie.rb
      invoke    rspec
      create    spec/models/movie_spec.rb

但是当我跑rails g model movie showtime_date:date showtime_time:time时 我得到了

invoke  active_record
      create    db/migrate/xxxxxxxxxxx_create_movies.rb
      create    app/models/movie.rb
      invoke    test_unit
      create      test/models/movie_test.rb
      create      test/fixtures/movies.yml

我的gem包有问题吗?我正在使用Rails4 beta。这个版本有错误还是其他什么?

我的应用的BDD就像这个app/features/show_descripitons.feature

Feature: Showtime Descriptions
    As a movie goer
    I want to see accurate and concise showtimes
    So that I can find movies that fit my schedule

    @wip
    Scenario: Show minutes for times ending with 00
        Given a movie
        When I set the showtime to "2013-05-04" at "2:15pm"
        Then the showtime description should be "June 04, 2013(2pm)"

    Scenario: Hide minutes for times ending with 00
        Given a movie
        When I set the showtime to "2013-05-04" at "2:00pm"
        Then the showtime description should be "June 04, 2013(2pm)"

我的app/features/step_definition/showtime_descriptions.rb就是这个

Given(/^a movie$/) do
    @movie = Movie.create!
end

When(/^I set the showtime to "(.*?)" at "(.*?)"$/) do |date, time|
    @movie.update_attribute(:showtime_date, Date.parse(date))
    @movie.update_attribute(:showtime_time, time)
end

Then(/^the showtime description should be "(.*?)"$/) do |showtime|
    @movie.showtime.showtime eq(showtime)
end

3 个答案:

答案 0 :(得分:10)

我应该将此代码放在config / application.rb

    config.generators do |g|
       g.template_engine :erb
       g.test_framework  :rspec, :fixture => true, :views => false
       g.integration_tool :rspec, :fixture => true, :views => true
       g.fixture_replacement :factory_girl, :dir => "spec/support/factories" 
     end

答案 1 :(得分:4)

嗯,我也遇到了4.1的类似问题。但最后,以下的票帮助我解决了这个问题。 https://github.com/rspec/rspec-rails/issues/439

简而言之,您必须确保rspec-rails组中的development不在test组中。通过这个小改动和bundle install,我得到了所有自动生成的spec文件。

答案 2 :(得分:0)

听起来您已经创建了rails项目后添加了RSpec。您需要删除测试单元生成器参考。确保您已运行rails g rspec:install并且config/application.rbhttp://edgeguides.rubyonrails.org/generators.html#customizing-your-workflow)中不包含以下内容:

g.test_framework  :test_unit, fixture: true

创建新的rails项目时,可以使用-T, [--skip-test-unit]标记省略测试单元。