Если помощники не должны работать - PullRequest
0 голосов
/ 12 сентября 2010

У меня есть одна спецификация:

require 'spec_helper'

# hmm... I need to include it here because if I include it inside describe block `method_missing` exception raises.
include Shoulda::ActionController::Matchers

describe CategoriesController do
  include Devise::TestHelpers

  render_views

  context "new should render template :new" do
    setup do
      sign_in :user
      get :new
    end

    should render_template(:new)
  end
end

, когда я запускаю rake spec, я вижу это (но если я изменяю контекст на него и перемещаю setup содержимое блока в it, блок работает нормально):

localhost:gallery rtest$ rake spec
(in /Users/rtest/Projects/gallery)
/Users/rtest/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S bundle exec  /Users/rtest/.rvm/rubies/ruby-1.9.2-p0/bin/ruby  -Ilib -Ispec "./spec/controllers/categories_controller_spec.rb" "./spec/controllers/photos_controller_spec.rb" "./spec/helpers/categories_helper_spec.rb" "./spec/helpers/photos_helper_spec.rb" "./spec/models/category_spec.rb" 
***

Pending:
  CategoriesHelper add some examples to (or delete) /Users/rtest/Projects/gallery/spec/helpers/categories_helper_spec.rb
    # Not Yet Implemented
    # ./spec/helpers/categories_helper_spec.rb:14
  PhotosHelper add some examples to (or delete) /Users/rtest/Projects/gallery/spec/helpers/photos_helper_spec.rb
    # Not Yet Implemented
    # ./spec/helpers/photos_helper_spec.rb:14
  Category add some examples to (or delete) /Users/rtest/Projects/gallery/spec/models/category_spec.rb
    # Not Yet Implemented
    # ./spec/models/category_spec.rb:4

Finished in 0.0006 seconds
3 examples, 0 failures, 3 pending
/Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb:41:in `renders_template?': undefined method `assert_template' for #<Class:0x00000104839eb0> (NoMethodError)
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb:23:in `matches?'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/handler.rb:11:in `handle_matcher'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/extensions/kernel.rb:27:in `should'
        from ./spec/controllers/categories_controller_spec.rb:17:in `block (2 levels) in <main>'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe'
        from ./spec/controllers/categories_controller_spec.rb:11:in `block in <main>'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe'
        from /Users/rtest/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/extensions/object.rb:7:in `describe'
        from ./spec/controllers/categories_controller_spec.rb:6:in `<main>'
Loaded suite /Users/rtest/.rvm/gems/ruby-1.9.2-p0/bin/rake
Started

Finished in 0.003418 seconds.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 39993

Мой spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda'
require 'shoulda/rails'
require 'shoulda/integrations/rspec2'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}


RSpec.configure do |config|
  # == Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, comment the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
end

Я использую рельсы 3. rspec / shoulda / factory_girl включены в приложение с помощью этого кода в Gemfile:

group :test, :development do
  gem 'autotest'
  gem 'factory_girl'
  gem "shoulda"
  gem "rspec-rails", ">= 2.0.0.beta.20"
end

Ответы [ 2 ]

3 голосов
/ 17 сентября 2010

Я почти уверен, что ошибка в том, что вы не заключили свое утверждение musta в блок it, например:

it { should render_template(:new) }

Требуется при использовании musta с RSpec.

should render_template(:new) самостоятельно будет работать с Test :: Unit.

0 голосов
/ 12 сентября 2010

Если я не ошибаюсь, я использовал Следует и думаю, что синтаксис

should_render_template(:new)

, а не

should render_template(:new)

, который объясняет 0 тестов, 0 утверждений...

...