在开发过程中,我希望在运行测试时看到sinatra应用程序异常,例如:
require 'sinatra/base'
class ExceptionWeb < Sinatra::Base
enable :raise_errors
enable :dump_errors
configure do
enable :dump_errors
end
get "/" do
raise "hell"
"ok"
end
def self.bad_m
我想做的是在命令行上运行ruby sayhello.rb,然后从Rspec接收Hello
我有这样的想法:
class Hello
def speak
puts 'Hello from RSpec'
end
end
hi = Hello.new #brings my object into existence
hi.speak
现在我想在rspec中编写一个测试,以检查命令行输出是否实际上是“Hello from rspec”
而不是“我喜欢Unix”
不工作。我目前在say
如果我的规范中有以下行
include Rack::Test::Methods
let(:competition_date) { Date.today+10.days }
如何在rspec中打印比赛日期符号的值?在rspec中,可以在之前的和之前的块中访问中定义的变量。所有内容都必须包含在描述块中,但如下所示:
describe "let variables" do
let(:competition_date) { Date.today+10.days }
it "shoul
在测试模块的rspec测试套件中,是用于评估包含该模块的类的行为的测试。下面是一个粗略的例子
describe "MyMod" do
module MyMod; end
shared_examples_for "a class" do |klass|
it "includes the module" do
klass.included_modules.include? MyMod.should be_true
end
end
describe
使用Rspec,是否有一种方法可以存根除第一个方法之外的所有方法调用
例如:
class Book
def foo
"Book#foo()"
end
end
规范中:
it 'x' do
# .... (do something to stub all but the first method call to `Book#foo`)....
b = Book.new
expect(b.foo).to eq('Book#foo()')
expect(b.foo
似乎在Capybara中使用send\u键总是首先在给定输入上触发单击元素
是否有办法绕过此问题,例如,当我知道我已将焦点设置为输入时(出于某种原因不希望触发单击事件)
顺便说一句,我使用的是PhantomJS。Poltergeist在向元素发送键之前单击该元素,以确保该元素处于焦点-。从代码中可以看到,如果元素已包含由定义的选择,则跳过单击。因此,跳过单击的唯一受支持的方法是确保所选内容已存在于要向其发送密钥的元素中。是否将PhantomJS与selenium一起使用?或者你是通过恶灵来使用它
是否有一种方法可以获得传递给测试主题的参数的句柄,然后对参数测试多个不同的期望?大概是这样的:
expect(foo).接收(:bar)
受试者。试验中的方法
expect(args\u将\u传递给\u foo)。将为散列\u,包括(键1:“某些值”)
expect(args\u传递给\u foo)。为散列\u,包括(key2:/some regexp/)
expect(args\u传递给\u foo.keys)。不包含(:key3)
期望(some_方法(args_传递给_-foo[:key4
标签: Rspec
textmatetextmatebundles
当我点击cmd-shift-t时,我看到rspec的go to symbol视图,我看到如下内容:
Project
context "with collaborators"
"should have mailing list"
请注意,应该有邮件列表在上下文下没有正确缩进。我想看到的是:
Project
context "with collaborators"
"should have mailing list"
我在bundler编辑器中使用了rspectextmate语法
给定以下RSpec配置(v2.12.0):
有时人们忘记从规范中删除:focus标记,在我们希望运行所有规范的持续集成环境中,只有带有剩余:focus标记的规范才能运行
我试过:
rspec --tag ~focus
。。。它运行所有规格,不包括标记为:焦点的规格
有没有一种方法可以使用rspec的命令行选项强制运行所有规范,忽略任何标记?您可以删除这些行:
config.filter_run :focus => true
config.run_all_when_everything
标签: Rspec
capybaracapybara-webkit
在具有Rspec 2.12.0的Capybara 2.1.0上:
如果我运行$rspec spec/features/user\u查看排行榜\u spec.rb,则规格通过
如果我运行$rspec spec/features/*,测试将失败,并声明:
Capybara::ElementNotFound:
Unable to find css "#flash"
如果我执行保存并打开页面,#flash将出现并可见
以下是发生故障的帮助器:
def sign_in_as(user)
vis
标签: Rspec
rspec2rspec-rails
如何从数组生成it测试
describe "some test" do
let(:some) { generated_array }
# raise error - undefined local variable or method
some.each do |key|
it "#{key} test" do
true
end
end
# will work
[1,2,3].each do |key|
...
end
如何用RS
要用所需的url检查当前url吗
describe "SEO Error" do
it "URL" do
visit 'http://localhost:4000/'
current_path.should == 'http://localhost:4000/'
end
end
得到的错误类似于
Failure/Error: current_path.should == 'http://localhost:4000/'
expected: "htt
我在我们庞大的代码库中发现了许多规范(有些甚至是我的:),它们忘记了包含。should,并且在没有测试任何东西时通过了
e、 g
由于未使用RSpec匹配器,因此无论response.body的内容如何,此规范都将通过
我的问题是:是否有一个RSpec选项或gem或其他东西可以检测规范何时完成,而不使用任何RSpec匹配器,也不调用pending,并引发错误或标记规范失败或其他一些状态,以提醒开发人员规范没有做他们可能认为的事情
接下来的问题是:这不应该是RSpec的默认行为吗?是否有一个用例,
我正在处理一个项目,在这个项目中,我们有两个rspec测试,都覆盖了Ruby代码,我们还设置了通过Grunt任务运行的karmajavascript单元测试
我已经设置好了,可以让它在运行grunt test和dryRun:true时生成一个local workalls.json。但是,我不确定如何配置我的工作服repo_令牌
我还有一个.workalls.yml,它成功地将rspec测试的报告发送到workalls
我不确定是否以及如何将rspec的保险报告和grunt karma报告发送给工
标签: Rspec
grape-apigrape-entity
响应主体返回“带Grape实体的格式化json”,但首选的第一个是返回完整的对象(json格式)
如何转换first\u preferred对象以使用grape实体获取公开字段
特征HomekeeperResponseEntity:
module API::V1::Entities
class FeaturedHomekeeperResponseEntity < Grape::Entity
expose :id, documentation: { type: 'integer'
我发现和方法对于链接许多期望非常有用
expect {
click_button 'Update Boilerplate'
@boilerplate_original.reload
} .to change { @boilerplate_original.title }.to('A new boilerplate')
.and change { @boilerplate_original.intro }.to('Some nice introduction')
有什么东西让我检查
标签: Rspec
capybaracapybara-webkit
我正在使用Capybara测试一个基本表单-当用户填写并提交表单时,它应该创建一个新的用户记录
it "creates a new user" do
visit some_random_path
# Fill In Form
fill_in("name", with: "foo bar")
fill_in("email", with: "foo.bar@example.com")
expect do
click_button("Submit")
end.to
在使用Capybara+RSpec编写测试框架/测试时,我遇到了以下建议,即测试不存在的元素:
expect(page).to have_no_button('Save') # OK
expect(page).not_to have_button('Save') # Bad
我不明白为什么,直到我看到这句话:
Use应该有带有RSpec匹配器的版本,因为不应该
have_*不等待驱动程序超时
这是真的吗?如果没有…从页面对象模型的角度来看,有一个方法来检查并返回是否存在(我通常使用.vi
上一页 1 2 ...
18 19 20 21 22 23 24 ...
下一页 最后一页 共 27 页