Amrit Dhungana
Amrit Dhungana

Reputation: 4485

Rspec not generating *_spec.rb file in Rails 4 beta

I have already install rspec-rails gem. When I run rails g model movie showtime_date:date showtime_time:time I think, I should get

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

But when I run rails g model movie showtime_date:date showtime_time:time I get

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

Is there a problem with my gem package? I am using Rails4 beta. Does this version have got error or something else?

The BDD for my app is like this 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)"

and my app/features/step_definition/showtime_descriptions.rb is this

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

Upvotes: 7

Views: 1598

Answers (3)

Derick
Derick

Reputation: 191

Well, I also faced a similar problem with 4.1. But in the end, following ticket helped me to resolve the issue. https://github.com/rspec/rspec-rails/issues/439

In short, you have to make sure that rspec-rails is in the development group and not only in the test group. With that small change and bundle install, I got all the spec files generated automatically.

Upvotes: 4

Amrit Dhungana
Amrit Dhungana

Reputation: 4485

I should put my this code in 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

Upvotes: 10

Aaron K
Aaron K

Reputation: 6971

Sounds like you added RSpec after you already created the rails project. You will need to remove the test unit generator reference. Make sure you have run rails g rspec:install and that the following is not in your config/application.rb (http://edgeguides.rubyonrails.org/generators.html#customizing-your-workflow):

g.test_framework  :test_unit, fixture: true

When creating a new rails project you can omit test unit with the -T, [--skip-test-unit] flag.

Upvotes: 0

Related Questions