Tag: rspec

水豚:我如何填写一个input字段的ID

我有这个: <input class="string optional" id="course_group_courses_attributes_2_name" name="course_group[courses_attributes][2][name]" placeholder="Lengua" size="15" type="text" /> </div> 我如何通过ID填写该字段?

RSpec:如何testing一个方法是否被调用?

在编写RSpectesting时,我发现自己写了很多代码,看起来像这样,以确保在执行testing期间调用一个方法(为了争辩,让我们只是说我不能真正的询问状态因为该方法执行的操作不容易看到效果)。 describe "#foo" it "should call 'bar' with appropriate arguments" do called_bar = false subject.stub(:bar).with("an argument I want") { called_bar = true } subject.foo expect(called_bar).to be_true end end 我想知道的是:有比这更好的语法吗? 我是否错过了一些时髦的RSpec迷人,将上述代码减less到几行? should_receive听起来应该这样做,但进一步阅读听起来像这不完全是什么。

在rails中使用RSpec和Capybara时未定义的方法`访问'

我不能得到水豚与rspec工作。 它给了我这个错误: undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil> 我知道有很多关于这个的post,但没有解决scheme正在为我工​​作。 他们中的大多数都涉及不在/规格/function的规格 – 这是我的。 首先是错误: $bundle exec rspec spec F Failures: 1) security signs users in Failure/Error: visit "/sessions/new" NoMethodError: undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil> # ./spec/features/security_spec.rb:4:in `(root)' Finished in 0.006 seconds 1 example, 1 failure Failed examples: rspec ./spec/features/security_spec.rb:3 # security signs users in 我认为重要的是要注意,一开始我使用URL […]

无法与RSpec比较时间

我正在使用Ruby on Rails 4和rspec-rails gem 2.14。 对于我的对象,我想比较当前时间与控制器操作运行后updated_at对象属性,但我有麻烦,因为规范没有通过。 也就是说,鉴于以下是规范代码: it "updates updated_at attribute" do Timecop.freeze patch :update @article.reload expect(@article.updated_at).to eq(Time.now) end 当我运行上面的规范,我得到以下错误: Failure/Error: expect(@article.updated_at).to eq(Time.now) expected: 2013-12-05 14:42:20 UTC got: Thu, 05 Dec 2013 08:42:20 CST -06:00 (compared using ==) 我怎样才能使规范通过? 注意 :我也尝试了以下(注意utc另外): it "updates updated_at attribute" do Timecop.freeze patch :update @article.reload expect(@article.updated_at.utc).to eq(Time.now) end 但规格仍然没有通过(注意“有”价值差异): […]

水豚断言元素的属性

我正在使用RSpec2和Capybara进行验收testing。 我想断言链接是禁用或不在水豚。 我怎样才能做到这一点?

RSpec:描述,上下文,function,场景?

describe , context , feature , scenario :四者之间有什么区别?我什么时候使用每一个?

在rspec中禁用一组testing?

我有一个testing规范, describes了一个类,其中有不同的contexts每个不同的块。 有没有办法可以暂时禁用context ? 我试图在我想禁用的context的最上面添加一个pending "temporarily disabled"调用,当我运行规范时,我确实看到了一些关于挂起的内容,但是它只是继续运行其余的testing。 这是我所拥有的: describe Something context "some tests" do it "should blah" do true end end context "some other tests" do pending "temporarily disabled" it "should do something destructive" do blah end end end 但就像我说的那样,它只是继续在挂起的呼叫下面运行testing。 search引导我到这个邮件列表线程 ,其中rspec的创build者(?)表示在rspec 2中,我正在运行它。 我想这样做确实有效,但是它并没有达到禁用所有以下testing的效果,这是我在看到一个pending呼叫时所想到的。 有没有其他的select,或者我做错了吗?

水豚歧义决议

如何解决水豚的歧义? 出于某种原因,我需要在页面中具有相同值的链接,但是由于出现错误,我无法创buildtesting Failure/Error: click_link("#tag1") Capybara::Ambiguous: Ambiguous match, found 2 elements matching link "#tag1" 我无法避免的原因是因为devise。 我正在尝试重新创buildTwitter页面的右侧的推文/标签和页面左侧的标签。 因此,同一页面上出现相同的链接页面是不可避免的。

RSpec控制器testing – 空白response.body

当用RSpectesting我的控制器时,我遇到了一个问题 – response.body调用总是返回一个空string。 在浏览器中一切正常呈现,黄瓜functiontesting似乎是正确的,但RSpec每次都失败。 响应对象的其他期望,如response.should render_template('index')通过没有任何问题。 你有没有遇到过这个问题? 也许响应的HTML可以通过其他方式获得? 至于版本,Rails 2.1.0,RSpec 1.2.7。

在大型Rails应用程序中加速RSpectesting

我的RSpectesting中有超过2000个示例的Rails应用程序。 不用说,这是一个很大的应用程序,还有很多需要testing的东西。 在这一点上运行这些testing是非常低效的,因为它需要这么长时间,所以在推新版本之前,我们几乎处于不鼓励写它们的地步。 我在spec.opts中添加了-profile来查找最长的运行示例,其中至less有10个平均需要10秒才能运行。 RSpec专家是否正常? 例如10秒完全太长了吗? 我意识到,用2000个例子来说,要彻底地testing所有的东西需要花费不小的时间 – 但是在这一点上4个小时是有点可笑的。 什么样的时候你看到你最长的例子? 我能做些什么来排除现有的规格,以便找出瓶颈并帮助加快速度。 现在每分钟都会有帮助。