man*_*eko 1 ruby-on-rails cucumber rspec2 ruby-on-rails-3.1
我是rails的新手,并开始了一个新项目.我有rspec2和黄瓜与我的测试工作没有问题.但是,如果我尝试添加guard-rspec和guard-cucumber,则会导致我的规范和集成测试失败.虽然,即使安装了防护装置,如果我手动运行rspec和黄瓜,测试都会成功.
我添加到我的gemfile:
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
Run Code Online (Sandbox Code Playgroud)
我跑了:
bundle
guard init rspec
guard init cucumber
Run Code Online (Sandbox Code Playgroud)
然后,当我跑卫,我得到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)>'
Run Code Online (Sandbox Code Playgroud)
我让黄瓜失败了:
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)
Run Code Online (Sandbox Code Playgroud)
看起来Guard似乎在某处弄乱我的工厂数据,因为以"the body必须超过50个字符"开头的文本在我的factory_girl工厂定义中.
编辑: 我发现rake如何调用rspec,而不是后卫.为什么会这样?
耙:
/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/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/DO cuments/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 /文档/ mattandreko.com /规格/路由/ tags_routing_spec.rb"
看起来你在测试之间清理数据的方式不起作用.
您是否可以在之前(:all)调用中创建数据?
Rake spec调用(除其他外)rake db:test:prepare,它将删除并重新构建数据库.呼叫守卫不会调用rake db:test:prepare.这就是你在数据库中看到不同状态的原因.
| 归档时间: |
|
| 查看次数: |
1162 次 |
| 最近记录: |