当我运行 rspec 运行所有测试时,它们都通过了,但是当我给出特定的文件名时,它会失败。
$ rspec spec/controllers/refinery/books/admin/books_controller_spec.rb
2) Refinery::Books::Admin::BooksController GET :new responds 200 success
Failure/Error: login_admin_user #Gives 404
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: POST http://localhost:8981/solr/default/update?wt=ruby with body '<?xml ...' with headers {'Content-Type'=>'text/xml'}
You can stub this request with the following snippet:
stub_request(:post, "http://localhost:8981/solr/default/update?wt=ruby").
with(:body => "<?xml ...",
:headers => {'Content-Type'=>'text/xml'}).
to_return(:status => 200, :body => "", :headers => {})
registered request stubs:
stub_request(:post, "http://localhost:8983/solr/test/update?wt=ruby").
with(:headers => {'Content-Type'=>'text/xml'})
============================================================
# ./lib/rsolr/connection.rb:15:in `execute'
# (eval):2:in `post'
# ./spec/support/controller_macros.rb:21:in `login_admin_user'
我已经对它进行了嘲笑和存根,为什么它会失败?我唯一能看到的是现有存根是“/test/”,请求是“/default/”。那是怎么改变的?
好的,我在另一个规范上再次遇到了这个问题。这是规范: https ://gist.github.com/starrychloe/1d79d9925f9b79ae5c01
我确实找到了这个 solr/solr.xml
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:}">
<core name="default" instanceDir="." dataDir="default/data"/>
<core name="development" instanceDir="." dataDir="development/data"/>
<core name="test" instanceDir="." dataDir="test/data"/>
</cores>
</solr>
就像 rspec 在生产环境中运行一样,即使我明确给出了环境
$ RAILS_ENV=test rspec spec/controllers/refinery/books/books_controller_spec.rb
我认为这是一个 rspec 问题。rspec -v
:版本 2.14.7。