shared_examples_for "test" do
specify { } # RSpec executes this line.
describe "nested" do
specify { } # RSpec doesn't execute this line.
describe "nested nested" do
specify { } # RSpec doesn't execute this line too.
end
end
end
这一切
在rspec 1中我可以做到
describe "Something", :shared => true do
include SomeModule # which has the :a_method method
def a_method(options)
super(options.merge(:option => @attr)
end
it "foofoofoo" do
end
end
describe "Something else" do
before(:each) do
@attr = :
我使用shared_examples_for在rspec中包含了模块中的常量
shared_examples_for 'Constants' do
include AllTestData.UserConstants
end
# for example I have AllTestData.UserConstants::USER_NAME = 'John Dorian'
describe Users do
include_context 'Constants'
p USER_NAME
end
当我使用ruby 1.9.2时,它可
我有一个Rails 3 admin_controller,它具有默认的CRUD、index等方法集。我想用rspec测试其中的每一个断言。
比如response.should render_template("layouts/some_layout")或者应该需要登录的测试。
将测试复制到每一种方法的测试组中是大量的重复。海事组织没有什么意义
it 'should require login' do
重复了几次那个测试。
是否有一种简单的方法来对一组方法进行测试?比如defined_methods.each do |method| it 'should&
我有一个正在构建的RESTful应用程序接口的Rails3.1应用程序。我们的计划是基于通过Authorization HTTP头传递给每个请求的API密钥来处理身份验证。为了在RSpec中测试这一点,我想在config.before块中设置request.env["HTTP_AUTHORIZATION"]属性:
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
config.before(:each) do
# Set A
我有一个像这样的规格
describe MyClass do
it_behaves_like SharedClass, MyClass.new
end
在我的共享示例规范中,我有
shared_examples_for SharedClass do |instance|
before do
instance.some_my_class_method = double
end
# some specs here
end
在MyClass实例中,有一些方法不能存根到shared_examples_for块中,所以我希望在将它们传递到it_behaves_like语句之前先
Rails 4.0.0;RSpec 2.14.x;Capybara 2.1.0
在果岭中重构/重组一些规范。
describe 'Visiting propane_fill_path' do
shared_examples_for 'with a recorded fill' do |fill_sym|
context 'when not signed in' do
include_examples 'visiting redirects to user sign in', :propane_fill_pa
请指导如何使用RSpec禁用以下测试方法之一。我使用Selenuim WebDriver + RSpec组合来运行测试。
require 'rspec'
require 'selenium-webdriver'
describe 'Automation System' do
before(:each) do
###
end
after(:each) do
@driver.quit
end
it 'Test01' do
#positive test case
end
我想这样做。
代码
describe "TestA" do
it "1" do
puts "in A-1"
end
it "2" do
next() # REMARK HERE!!
# I want to skip this example group from here.
puts "in A-2"
end
end
describe "TestB" do
it "1" do
puts "in
我是一个新手,水豚,rspec集成测试。如何使用动态计算的参数调用共享示例?
shared_examples_for "a measurable object" do |example, display_name|
it "is example - #{display_name}" do
visit "www.example.com?args=test"
expect(page.find("#examplediv").text).to eq example
end
end
describ
我正在尝试添加一个函数,以便快速测试未经身份验证的用户的重定向。到目前为止,我的情况如下:
def unauthenticated_redirects_to redirect_path #yeild
context "when not signed in" do
it "redirects to #{redirect_path}" do
yield
expect(response).to redirect_to redirect_path
end
end
end
describe SomeController
我使用Rails 5和功能测试RSpec/Capybara/Poltergeist/Selenium。在本地,在我手动安装必要的geckodriver之后,测试运行得很好。
但在TravisCI上,RSpec测试失败,并显示以下错误消息:
Selenium::WebDriver::Error::WebDriverError:
Unable to find Mozilla geckodriver. Please download the server from
https://github.com/mozilla/geckodriver/releases and place it
在我的Rails 3应用程序中,我有一个RSpec规范,它检查给定字段(用户模型中的角色)的行为,以确保该值在有效值列表中。
现在,我将在另一个具有另一组有效值的模型中,为另一个字段提供完全相同的规范。我希望提取通用代码,而不是仅仅复制和粘贴它,更改变量。
我想知道是否应该使用共享示例或其他RSpec重用技术。
下面是相关的RSpec代码:
describe "validation" do
describe "#role" do
context "with a valid role value" do
it "
我有一个这样的规范:
shared_examples_for 'using the id' do |the_id|
it 'should do something with the id' do
# do something with the_id
end
end
id = nil
describe 'a spec' do
it 'should retrieve id' do
id = getId
expect(id).to eq(12345)
en
RSpec说,有了我的帮助页面,一切都很好,但事实并非如此。什么会导致假阳性。(我已经多次重启了我的测试套件)。
这是我的规范页面:
require 'spec_helper'
describe "Static pages" do
subject { page }
shared_examples_for "all static pages" do
it { should have_selector 'h1', text: heading }
it { should have_selector &
我想用RSpec测试跟随控制器
coupons_controller.rb:
class Api::V1::CouponsController < ApiController
def index
if params[:profile_id]
@coupons = Profile.find(params[:profile_id]).coupons
end
end
end
我想知道
1)如何使用FactoryBot (spec/factories/profiles.rb、coupons.rb、coupon_profiles.rb)创建工厂
2)如何编写sp
RSpec有一种很好的方法,通过在配置中使用filter_run_excluding排除单个测试/示例或整个组,然后对示例进行标记:
示例:
RSpec.configure do |c|
c.filter_run_excluding :xcode => true
end
RSpec.describe "something" do
it "does one thing" do
end
it "does another thing that needs xcode", :xcode => true
我是测试和使用RSpec的新手,需要一些帮助:
我已经分享了示例组:
shared_examples_for 'request which do something' do |opts = {}|
respond.should redirect_to(opts[:redirect_to])
end
在我的规范文件中:
describe "behavior" do
it_should_behave_like 'request which do something', :redirect_to => root_path
end
看起来很
如果我让工厂女孩为主持人做它的标准衬里,它就会失败,抱怨save!没有实现。
是否可以自定义演示者的线型,使其只检查是否能够成功构建演示程序,而不保存它?
演示者
class PostPresenter
def initialize(post)
@post = post
end
end
工厂
FactoryGirl.define do
factory :post_presenter do
post
initialize_with { new(post) }
end
end
回溯
/Users/agrimm/.rbenv/versions/2.2.0/li