加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rspec在Rails 4 beta中没有生成* _spec.rb文件

发布时间:2020-12-17 04:33:50 所属栏目:百科 来源:网络整理
导读:我已经安装了rspec-rails gem.当我运行rails g model movie showtime_date:date showtime_time:我想的时间,我应该得到 invoke active_record create db/migrate/20130604010556_create_movies.rb create app/models/movie.rb invoke rspec create spec/mod
我已经安装了rspec-rails gem.当我运行rails g model movie showtime_date:date showtime_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

解决方法

我应该将此代码放在config / application.rb中
config.generators do |g|
       g.template_engine :erb
       g.test_framework  :rspec,:fixture => true,:views => false
       g.integration_tool :rspec,:views => true
       g.fixture_replacement :factory_girl,:dir => "spec/support/factories" 
     end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读