Tag: 存根

Oauth模型关注测试覆盖存根

我试图找出在这个课程上达到100%测试覆盖率的最佳方法。 我概述了我的完整规范,我希望有人可以指出我正确的方向。 我的假设是将Oauth2请求存根,但我似乎无法做到这一点。 我正在使用Rails 4。 规格 RSpec.describe ‘AppOmniAuthentication’, type: :concern do let(:klass) { User } let(:user) { create(:user) } let(:user_oauth_json_response) do unfiltered_oauth_packet = load_json_fixture(‘app_omni_authentication_spec’) unfiltered_oauth_packet[‘provider’] = unfiltered_oauth_packet[‘provider’].to_sym unfiltered_oauth_packet[‘uid’] = unfiltered_oauth_packet[‘uid’].to_i unfiltered_oauth_packet end before do OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:app] = OmniAuth::AuthHash.new( user_oauth_json_response, credentials: { token: ENV[‘APP_CLIENT_ID’], secret: ENV[‘APP_CLIENT_SECRET’] } ) end describe ‘#from_omniauth’ do let(:app_oauth) { […]

使用mocha存根实例变量

假设我有一个直接引用实例变量的方法: class MyClass def method1 puts @instance_var end end 如何在Test::Unit测试中使用mocha来@instance_var的值?

Stub(…)收到意外消息(…)(没有args)

我尝试使用RR编写测试。 我需要的是模型对象的存根。 describe ApplicationController do subject(:application_controller) { ApplicationController.new } let(:messages) { [‘a1’, ‘a2’, ‘a3’ ] } let(:model) { Object.new } it ‘should copy errors to flash’ do stub(model).error_messages { messages } flash[:error] == nil subject.copy_errors_to_flash(model) flash[:error].should == messages end end 我得到的是 ApplicationController should copy errors to flash Failure/Error: stub(model).error_messages { messages } Stub # received […]

存根和rspec旧语法的问题

我正在编写一些代码并使用rspec,但收到一个警告,语法是旧的,我不知道我应该如何编写它? it “should calculate the value correctly” do mock_cards = [Card.new(:clubs, 5), Card.new(:diamonds, 10)] hand = Hand.new hand.stub(:cards) { cards } #stub out cards and have it return cards expect(hand.value).to eq (15) end 错误消息如下:使用来自rspec-mocks’old的stub :should不使用显式启用语法的语法。 使用new :expect语法或显式启用:should改为。

有没有办法在Test :: Unit中撤消任何实例的Mocha存根

就像这个问题一样 ,我也在使用Ryan Bates的nifty_scaffold。 它具有使用Mocha的any_instance方法强制在隐藏在控制器后面的模型对象中的“无效”状态的理想方面。 与我链接的问题不同,我没有使用RSpec,而是使用Test :: Unit。 这意味着这两个以RSpec为中心的解决方案对我不起作用。 是否有一般(即:使用Test :: Unit)方法来删除any_instance存根? 我相信它在我的测试中导致了一个错误,我想validation一下。