Я новичок в рельсах и начинаю новый проект. У меня rspec2 и огурец работают с моими тестами без проблем. Однако, если я попытаюсь добавить guard-rspec и guard-cucumber, это приведет к сбою как моих спецификаций, так и интеграционных тестов. Хотя даже с установленной защитой, если я запускаю rspec и огурец вручную, все тесты проходят успешно.
Я добавил в свой гем-файл:
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'growl', :require => false if RUBY_PLATFORM =~ /darwin/i
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
Я побежал:
bundle
guard init rspec
guard init cucumber
Затем, когда я запускаю охранника, я получаю сбой rspec:
Failures:
1) PostsController GET index assigns all posts as @posts
Failure/Error: assigns(:posts).should eq([post])
expected [#<Post id: 14, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 19:02:46">]
got [#<Post id: 1, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 2, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 3, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 4, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 5, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">]
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-[#<Post id: 14, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 19:02:46">]
+[#<Post id: 1, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 2, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 3, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 4, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">, #<Post id: 5, title: "Title", body: "The body must be over 50 characters long, or else i...", created_at: "2011-08-16 09:02:26", updated_at: "2011-08-17 18:56:51">]
# ./spec/controllers/posts_controller_spec.rb:29:in `block (3 levels) in <top (required)>'
И у меня огурец не получается:
Running all features
Disabling profiles...
..F-----------
(::) failed steps (::)
expected there to be content "Test Title" in "Listing posts\n\nTitle\n Body\n Created at\n \n \n \n Title\n The body must be over 50 characters long, or else it will fail validation. This string should be adequate.\n 2011-08-16 09:02:26 UTC\n Show\n Edit\n Destroy\n Title\n The body must be over 50 characters long, or else it will fail validation. This string should be adequate.\n 2011-08-16 09:02:26 UTC\n Show\n Edit\n Destroy\n Title\n The body must be over 50 characters long, or else it will fail validation. This string should be adequate.\n 2011-08-16 09:02:26 UTC\n Show\n Edit\n Destroy\n Title\n The body must be over 50 characters long, or else it will fail validation. This string should be adequate.\n 2011-08-16 09:02:26 UTC\n Show\n Edit\n Destroy\n Title\n The body must be over 50 characters long, or else it will fail validation. This string should be adequate.\n 2011-08-16 09:02:26 UTC\n Show\n Edit\n Destroy\n ← Previous 1 2 3 4 5 6 Next →\n\nNew Post\n\n\n" (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:107:in `/^(?:|I )should see "([^"]*)"$/'
features/Homepage.feature:17:in `Then I should see "Test Title"'
Failing Scenarios:
cucumber features/Homepage.feature:6 # Scenario: Viewing the index page with paging
1 scenario (1 failed)
14 steps (1 failed, 11 skipped, 2 passed)
Похоже, что Guard каким-то образом вмешивается в мои заводские данные, поскольку текст, начинающийся с «Тело должно содержать более 50 символов», находится в моем определении factory_girl.
РЕДАКТИРОВАТЬ: Я обнаружил, что существуют различия в том, как rake вызывает rspec и guard. Почему это могло быть?
Грабли:
/Users/mandreko/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -S bundle exec rspec ./spec/controllers/posts_controller_spec.rb ./spec/controllers/tags_controller_spec.rb ./spec/helpers/ posts_helper_spec.rb ./spec/helpers/tags_helper_spec.rb ./spec/models/post_spec.rb ./spec/models/tag_spec.rb ./spec/requests/posts_spec.rb ./spec/requests/tags_spec.rb ./spec/requests/tags_spec.rb. spec / routing / posts_routing_spec.rb ./spec/routing/tags_routing_spec.rb ./spec/views/posts/edit.html.erb_spec.rb ./spec/views/posts/index.html.erb_spec.rb ./spec/ views / posts / new.html.erb_spec.rb ./spec/views/posts/show.html.erb_spec.rb ./spec/views/tags/edit.html.erb_spec.rb ./spec/views/tags/index .html.erb_spec.rb ./spec/views/tags/new.html.erb_spec.rb ./spec/views/tags/show.html.erb_spec.rb
Сторожить:
/Users/mandreko/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -rrubygems -S /Users/mandreko/.rvm/gems/ruby-1.9.2-p290@rails31rc5/gems/rspec-core -2.6.4 / bin / rspec --tty '/Users/mandreko/Documents/mattandreko.com/spec/controllers/posts_controller_spec.rb' '/Users/mandreko/Documents/mattandreko.com/spec/controllers/tags_controller_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/helpers/posts_helper_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/helpers/tags_helper_spec.rb '' / Users / mandreko / Documents / mattandreko .com / spec / views / posts / edit.html.erb_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/views/posts/index.html.erb_spec.rb '' / Users / mandreko / Documents /mattandreko.com/spec/views/posts/new.html.erb_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/views/posts/show.html.erb_spec.rb '' / Users / mandreko /Documents/mattandreko.com/spec/views/tags/edit.html.erb_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/views/tags/index.html.erb_spec .rb '' /Users/mandreko/Documents/mattandreko.com/spec/views/tags/new.html.erb_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/views/tags/show.html .erb_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/models/post_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/models/tag_spec.rb '' / Users / mandreko /Documents/mattandreko.com/spec/requests/posts_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/requests/tags_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/routing /posts_routing_spec.rb '' /Users/mandreko/Documents/mattandreko.com/spec/routing/tags_routing_spec.rb '