-
3 votesanswersviews
Rspec link_to - 包括confirm / data-confirm属性导致测试失败
我有一个如下链接,我正在尝试测试(请忽略方括号): [%= link_to“删除用户”,destroy_user_account_path(@ profile.user),:class =>“delete”,:confirm =>“a”,:title =>“删除#{@profile.user.name}” ,:method =>:delete%] 下面的测试失败,但如果... -
1 votesanswersviews
在rspec中将存根与断言分开
我正在使用rspec和rspec模拟库来进行存根/模拟,但是我开始认为存在一个方法并声明它如何被使用之间的界限是模糊的 . 在我的测试中,我经常写一些类似于: before(:each) do subject.should_receive(:sum).once.with([1, 2, 3]).and_return(6) end it("should do something tha... -
0 votesanswersviews
需要在rspec中调用stub()和should_receive()以获取视图部分规范
我在rspec(v2.8)中与should_receive()有些混淆 我的理解是它既存在方法 - 就像stub()那样 - 并设置了这个存根方法将被调用的期望 . 但是,在尝试使用它来截断从视图partial调用的辅助方法时,我不断收到错误: Failure/Error: render 'invitations/header' ActionView::Template::Error: u... -
4 votesanswersviews
如何使用RSpec和Capybara定位本地化按钮?
我正在使用RSpec和Capybara进行Ruby on Rails测试 . 我的Rails应用程序已针对多种不同语言(英语,德语等)进行了本地化 . 例如,我希望Capybara提交表单,但显然不能使用其值来选择它,因为值会根据所选语言而改变 . 这在我的情况下不起作用: click_button("Create my account") 有没有办法简单地选择Capybar... -
5 votesanswersviews
RSpec:未定义的方法`assert_difference'for ...(NoMethodError)
context 'with event_type is available create event' do let(:event_type) { EventType.where( name: 'visit_site').first } assert_difference 'Event.count' do Event.fire_event(event_type, @sponge,{... -
92 votesanswersviews
如何让rspec-2提供与测试失败相关的完整跟踪?
现在,如果我使用 rake spec 运行我的测试套件,我收到一个错误: 1) SegmentsController GET 'index' should work Failure/Error: get 'index' undefined method `locale' for # # ./spec/controllers/segments_controller_spec.rb:... -
33 votesanswersviews
Rails - RSpec - “let”和“let!”之间的区别
我已经阅读了RSpec manual关于差异的说法,但有些事情仍然令人困惑 . 每个其他来源,包括"The RSpec Book"只能解释"let",而"The Rails 3 Way"与手册一样令人困惑 . 我知道"let"仅在调用时进行评估,并在范围内保持相同的值 . 所以有意义的是,在manual的第一个例子中,... -
3 votesanswersviews
Rspec - 在另一个let语句中使用let语句中定义的变量
在我的RSpec测试中,我使用let()语法定义了多个方法 . 我遇到过一个场景,我需要将let语句中定义的变量用于同一个describe块中的另一个let语句 . context 'Reuse the name of first car in the second car' do it_behaves_like 'some car test' do let(:car1) d... -
67 votesanswersviews
Rails 3.1,RSpec:测试模型验证
我已经在Rails中使用TDD开始了我的旅程,并且遇到了一个关于模型验证测试的小问题,我似乎无法找到解决方案 . 假设我有一个用户模型, class User < ActiveRecord::Base validates :username, :presence => true end 和一个简单的测试 it "should require a username&quo... -
1 votesanswersviews
路由规范中未定义的方法`断言'
1) JunksController routing routes to #index Failure/Error: get("/junks").should route_to("junks#index") NoMethodError: undefined methodassertions' for #<#Class:0x007ff8d62c8568:... -
-1 votesanswersviews
将变量传递给rspec测试
我是一个相当新的rspec测试,我有一个问题,试图测试用户的位置 . 这是一个模拟country_code阻止特定区域垃圾邮件行为的测试 . 这是我的服务代码: class GeocodeUserAuthorizer def initialize(user_country_code:) @user_country_code = user_country_code end de...