我正在尝试将代码气候测试报告器添加到我正在使用CircleCI的Rails应用程序中。
我已经按照设置说明以及 CircleCI 运行时收到的错误消息进行操作,但是,我现在有点卡住了。我的测试都通过了(本地和 CircleCI),但我仍然收到错误。
有没有人看到这样的错误?如果是这样,关于让代码气候测试报告器与 CircleCI 正常工作有什么建议吗?正如错误输出所暗示的那样,我已经在我的 spec_helper.rb 中存根了响应。
感谢您的帮助。如果我需要包含更多信息,请告诉我。
以下是Code Climate所说的完成的步骤以及错误输出:
-
添加代码气候宝石
宝石列表代码气候测试报告器
codeclimate-test-reporter (0.5.0)
-
在 spec_helper.rb 中添加测试报告器(您还可以在底部的 config.before(:each) 块中看到错误消息中的stub_request。这是我的spec_helper.rb。
需要"代码气候测试报告器"
CodeClimate::TestReporter.start
ENV['RAILS_ENV'] = 'test'
需要 File.expand_path('../../config/environment', FILE)
需要"rspec/rails"
需要"应该/匹配者"
需要"Webmock/rspec"Dir[Rails.root.join('spec/support/**/*.rb')].each { |file| require file }
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.语法 = :期望
结束config.include Features, type: :feature config.include Formulaic::D sl, type: :feature
config.infer_base_class_for_anonymous_controllers = 假
config.order = 'random'
config.treat_symbols_as_metadata_keys_with_true_values = 真
config.use_transactional_fixtures = 假config.before(:each) do
stub_request(:p ost, "https://codeclimate.com/test_reports").
with(:body => "\u001F\x8B\b\u0000\xE0\xC1\u0012W........ :headers => {'Accept'=>'/', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Encoding'=>'gzip', 'Content-Type'=>'application/json', 'User-Agent'=>'Code Climate (Ruby Test Reporter v0.5.0)'})。
to_return(:status => 200, :body => ", :headers => {})·
结束 结束活动记录::Migration.maintain_test_schema!Capybara.javascript_driver = :webkit
WebMock.disable_net_connect!(allow_localhost:真)
代码气候测试报告 器令牌(我将其从代码气候测试报告器设置屏幕复制到 CircleCI 环境变量屏幕)
CODECLIMATE_REPO_TOKEN xxxxb0c8
这是我从 CircleCI 输出的错误:
bundle exec rspec --color spec --format progress
I, [2016-04-18T05:16:18.343024 #12231] INFO -- : Reporting coverage data to Code Climate.
/home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/activesupport-4.1.1/lib/active_support/values/time_zone.rb:285: warning: circular argument reference - now
[Simple Form] Simple Form is not configured in the application and will use the default values. Use rails generate simple_form:install to generate the Simple Form configuration.
.............
Finished in 1.24 seconds
13 examples, 0 failures
Randomized with seed 45226
Coverage = 100.0%. Sending report to https://codeclimate.com for branch contact_form... /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/webmock-1.24.0/lib/webmock/http_lib_adapters/net_http.rb:114:in request': Real HTTP connections are disabled. Unregistered request: POST https://codeclimate.com/test_reports with body '���mW��X�n�8�=g�/����á#DC�����5m�X�s���"%��3g�P���y�������h����8��1j�N��d}A (WebMock::NetConnectNotAllowedError)
*{UP�:Z��P]TӰ��Ҵ4U�_�:�W�v{�C?�C��8]�}� ������c�w�vHu�yU�EA2Ep)��"xk�JK# L
�E8����[_�E�kۧ���?gP���;���Z
q)�ǧy�~3���e�mz�����<T�0C[]�_�kuQu�4-�����(�-�-�l:T�D&�(�ǐ���+�iހ��)��
�>�?��Z��@-�H�D$��R,
����&.��ȂYO�"z�U�D,�����p���ĕ�7��u��Pa�-�8|���Yx���
:��c���p,��|0����20�B 9����WG��/���K���� �T��z#t�Fert��d��z�6��� �}F2�/I�8���
�M�s*�����b�]�S1���y���}��h�
{qt�#�3�O<��6���F�@��$��<�
w�dn��G�-.@2K��D������W�|���adڮ�3h�X�m���J��K�X��m���C�~��>E��(_/�q�װ��8��A�+�q�ڸ�ዊ��P��.�NtQm�yY{C��D2x�BK��D,1��J"'�W�K�g����k�w���X��4B�7O�4�uƮ�o�5>��˭O]��-��-!�z{����f��j���?�g���дS=r�{j��t[.r�ݫ37���E4x����b�-6�C�k����d^3b��B�]�ff�iJC#?�KU�=���xO���� �@��' with headers {'Accept'=>'/', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Encoding'=>'gzip', 'Content-Type'=>'application/json', 'User-Agent'=>'Code Climate (Ruby Test Reporter v0.5.0)'}
You can stub this request with the following snippet:
stub_request(:post, "https://codeclimate.com/test_reports").
with(:body => "u001Fx8Bbu0000xA5mu0014Wu0000u0003xCDXxDBnxDB8u0010xFDu0017=gu0013xDE/xF9x95xA2u0010x86á#Du0017Cx92x93xEEu0006xF9xF7u001D5mxE3XxB5sx81x83u0016u0001fx89"%x9ExE1x993gxF2Px8DxB4u001DxEAyxB8xA5xBExBAxAEx82xA1h\x88x94u001Dx99u0012xD08ex8BxD71jx90Nx89u0000d}A n*{u0011UPu000Ex92u0017:ZxE7x93xC0P]TӰex91xEAҴ4UxD7_u001ExAAu001E:xE2WxC3v{x85C?x8FCxDBxD28]xF1}xDB xCCxCDxD0xD7xCFxE3x97cxE2wxA4vHux93yUu000ExDAEA2Ep)xE7u0000"xkx92u000EJKu001F# u0015Lnx96E8xDCxD1bx9BxE5[xE4ExBFkۧx9FxA7xEBxAF?gPxAExB7xC4;xECxE7xEAZnq)x9EǧyxA4~3xDFxF0x83exB8mzxE2xADxEDxFAx99x81xF3xABkuQuxCD4-x97xE2xF1xF1xE2(xD6-xE0-xEFl:u0001TxC5D&xA1(xC1ǐxB4xCCxCE+xE9u0012ifހu0000xE9)u0005xADxCBnxE8>xD4?u000ExF4x9EZu001CxBAx93@-xB3HxE5D$xB4xC4R,nT!&xA9x9DxC6bxB2xCBIxA5xE0xD2xFADxFF8xD0ejxB7x87xCC}u001A[xB1x96xF8xE4|4u0016u001DxD8xC8aJI0UxA5xF7xB9萄xA5u0018Pu0015xF1[֞rx97xDAxC3%x8FxE0xE2s*xCDfu001FxD2!u0016']u0006#|xC9%xBAཊx85xF7P4)x95DdqxC8Y#x9CxCCxC0翗gxB8x9FxA1xFBu0013xE4zxE1xB1xC5u001FxFB9[x90x8DxD9gx8F8u001DxE64fxF3*u001FxC8u0016x81xB2u0000x8Ax84x99lx88xDAY-x80x83^2xE7JB(u0016x9C9x88xEFx8B0x9Du000FxCDeRxE1au0016xEAxEFx9AqxE8;xFExD6!$.u000F9x8Ax8CxCExCAhxB8DxC4"9xA5cxB4xBAu0014axBC7xE4xB5xD7u009Fx80tf\oIxF15xAExE9jxA6ix85.gfu0010xB5xB2Vu0014xCFURu0018k#xA7Dx88^u0014祱xB2PRx87axF6u001A{OxA6Ưl8~xF7xBE7u001Dx9Fq>.xC9}xFDy%xEAMxDFxCCrxB4xCDu007Fx8BxC0&.x97xF3ȂYOxEC"zxE4xB1UxD6Du001D,xB2x9AxFAx98xB2pu0010xB2xD2xCAĕxB57xF3u0013x9BuxB1xE9PaxCF-fxE28|xBFx87xFEu0015Yxu0001u001Ex87xE1xB6xE1n:xD1xF8cxECu0010xBBx87u0005p,xA2xC4\|0x89x8Dx99xCF20xE7Bt9xA0xF7x82x92WGxB1x9F/xAFxF4xDBKxCCvx90xB9x99 xB5Tu007FxEBxDAzv#txABu0003FertxECxFAu001CdxABu0014bxE5u0005zx926x82x8FxD2tx91}F2xF6/u0006IxE38xACx99xEBx93nĞx80MxB3s*xB3xB6x87u0000xD2u0006bxE9xB0]xC2S1xF4xAAxFFyxAFx94xBC}xD2xE7hxB0n{qtxEFx88#xB7u00123x8DO<xA1xE5xAAu001D6x9BxA6xDFu001CFxD6@x8Cx86$xF9x94<x92nxCCu000Fd/rxD9u0004nu001FBx94Lu0019B+OkxC2xE7u0014xD3xF7xF0xA6xE9KKxB8xxB1u0015yxD8$hx9D8xEF1u0018'x85xD4Jdx8Fx89u0014X.SxE0eBu0011ûexEFu0013xCDxD3tx8Dx94xEEx83"xD95u001DxD5xF3xBF[ZE(xA3fx91x8D*[Sx89u001Au001Cx8Bx88xD7u0005x8A7x8Ex94xB6%9SxD0xE4xE3xE2x~x94xE6x83 xB9u0002xDExD63#u001Dv+u0013u0002ƸxC51jx8A9bu0015ـx8BxA0،(u001FbxB5WYx92TJu001FxAAxC8xD9xC8-?Hiix9CxA6yu0018xE9u0010UxC8Fr)/ML1xB1xC2sxF7+x8CJx890xE5u0014QxA2/Eu001ExF6u001Au007Fx93xE8ߏxB0}x96xAAu0015=5u001Frwu007FxB6dnx9ExA2GxEC-u0015.u0004u000E@2Kx83xA4DxD1xFCxD6u001Ax9FxD0xEBWu0014xFF|xA7xFEx8Eu0006adڮxF33hxE7Xx8Fmu0006x9FxBDxF1Jx98x94KxF1u0005XxD5u0002u001AxB6mx8Bx9Dx81Cx91~xEExFF>Ex9ExF5v(_/xAAqxD7װxBCxD88u0011xADxB3Ax9E+x82qxBFfڸxFFዊx89xB3PxA9xBA.xD0NtQmx9AyY{CxF0xFDu007FD2xxCCBKu0003xE4xC0D,1xA5xECJ"'u0012xB7Wx85Ku0000gx88xFBu001ExA1xAEkxE6x99wxB5x87xC2XxD6xDB4Bx8F7OxC74u0003xCEuu0019ƮxE2oxEF5>xDFxF7˭O]u0016u001ExDFu000FxE3-xCFu001FxA7-!xBFz{xBFxECxE5xEAfxE8xE8jx97u0018xDExF2?x8CgxF7x8Du001Fx8FдS=rxA7{jxD6xD4t[.rxC3ݫ37xD4xD5u001CxADE4xx9AxB8xB4x97bxD9-6x8BCxBEkx90x96xCDxFEd^3bx8BxCDBxB8]xD3ffu001Cx83iJC#?x94KUxFC=xFAx9FxF1xAAxA7exOx9Cu001Fu001FxFFax94xB3txA6@u0015u0000u0000",
:headers => {'Accept'=>'/', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Encoding'=>'gzip', 'Content-Type'=>'application/json', 'User-Agent'=>'Code Climate (Ruby Test Reporter v0.5.0)'}).
to_return(:status => 200, :body => "", :headers => {})
============================================================
from /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/codeclimate-test-reporter-0.5.0/lib/code_climate/test_reporter/client.rb:67:in post_results'
from /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/codeclimate-test-reporter-0.5.0/lib/code_climate/test_reporter/formatter.rb:29:informat'
from /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/result.rb:47:in format!'
from /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/configuration.rb:172:inblock in at_exit'
from /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/defaults.rb:67:in call'
from /home/ubuntu/msd-redux/vendor/bundle/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/defaults.rb:67:inblock in '
((bundle exec rspec "--color" "" "spec" --format "progress")) returned exit code 1
根据代码气候文档,您需要允许 webmock 发出外部请求:https://docs.codeclimate.com/v1.0/docs/test-coverage-troubleshooting-tips#section--known-error-messages- 。话虽如此,您需要在调用之前添加WebMock.allow_net_connect!
或WebMock.allow_net_connect!(:net_http_connect_on_start => true)
CodeClimate::TestReporter.start
(在这种情况下,我认为您必须确保您的网络模拟配置正确。