在RSpec 3上迁移后,请求测试失败.这是我的测试
describe 'GET /api/v1/activities' do
let!(:user) { create(:user) }
subject { json['activities'] }
context 'when not authenticated' do
let(:token) { user.authentication_token }
let(:email) { 'unregistered.user@mail.com' }
before :each do
get '/api/v1/activities', {}, {token: token, email: email}
end
it { expect(response).to_not be_success }
end
end
Run Code Online (Sandbox Code Playgroud)
这是rspec日志
Activities GET /api/v1/activities when not authenticated
Failure/Error: get '/api/v1/activities', {}, {token: token, email: email}
NoMethodError:
undefined method `get' for #<RSpec::ExampleGroups::Activities::GETApiV1Activities::WhenNotAuthenticated:0x0000000becfaf8>
Run Code Online (Sandbox Code Playgroud)
它能是什么?
在使用RSpec 3和Capybara的Rails 4功能规范中,如何断言页面中是否存在一定数量的特定标签?
我试过了:
expect(find('section.documents .document').count).to eq(2)
Run Code Online (Sandbox Code Playgroud)
但这是行不通的,它说:
Ambiguous match, found 2 elements matching css "section.documents .document"
Run Code Online (Sandbox Code Playgroud)
另外,在功能规范中测试某些特定的东西(例如视图中使用的标记和类)是否是个好主意/不好的做法?
在rails 4.2.0/rspec 3.2.2/rspec-rails 3.2.1中.我正在尝试禁用生成新模型时生成的规范.我正在使用与rails约定不同的spec文件夹结构,并且不想为每个新模型删除/移动生成的spec文件.我尝试添加rails指南中提到的生成器配置,以及在运行`rails generate controller`时跳过创建测试,资产和帮助程序的语法是什么?
我的config/application.rb包含这个:
config.generators do |g|
g.test_framework :rspec
g.model_specs false
g.view_specs false
g.helper_specs false
g.controller_specs false
g.model_spec false
g.helper_specs false
g.request_specs false
g.feature_specs false
end
Run Code Online (Sandbox Code Playgroud)
而且我还在:
$rails g model category
invoke active_record
create db/migrate/20150416174523_create_categories.rb
create app/models/category.rb
invoke rspec
create spec/models/category_spec.rb
invoke factory_girl
create spec/factories/categories.rb
Run Code Online (Sandbox Code Playgroud)
即使我明确添加标签:
$rails g model category --no-model-specs
invoke active_record
create db/migrate/20150416174908_create_categories.rb
create app/models/category.rb
invoke rspec
create spec/models/category_spec.rb
invoke factory_girl
create spec/factories/categories.rb
Run Code Online (Sandbox Code Playgroud)
有人解决过这个吗?
慢速运行测试对于明显的问题是不可取的 但是默认情况下,RSpec没有给出关于个人测试速度的指示,只给出了摘要信息.
如何改变这一点并获得prfiling信息,以便找到负责慢速运行测试套件的测试?
我需要帮助使用 Faraday gem 来存根请求。我正在提出这个请求
URL='https://secure.snd.payu.com//pl/standard/user/oauth/authorize'.freeze
url_encoded = 'grant_type=client_credentials' \
+ "&client_id=#{ENV['client_id'}" \
+ "&client_secret=#{ENV['client_secret'}"
connection = Faraday.new do |con|
con.response :oj, content_type: /\bjson$/
con.adapter Faraday.default_adapter
end
connection.post(URL, url_encoded)
Run Code Online (Sandbox Code Playgroud)
哪个输出
#<Faraday::Response:0x00000000016ff620 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body={"access_token"=>"00a4e007-220b-4119-aae8-3cb93bb36066", "token_type"=>"bearer", "expires_in"=>43199, "grant_type"=>"client_credentials"} @url=#<URI::HTTPS https://secure.snd.payu.com/pl/standard/user/oauth/authorize> @request=#<Faraday::RequestOptions (empty)> @request_headers={"User-Agent"=>"Faraday v0.17.1"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00000000016ff620 ...> @response_headers={"set-cookie"=>"cookieFingerprint=70a4a8d1-7b05-4cb9-9d5c-5ad12e966586; Expires=Fri, 25-Dec-2020 09:31:02 GMT; Path=/; ; HttpOnly, payu_persistent=mobile_agent-false#; Expires=Sun, 20-Dec-2020 09:31:02 GMT; Path=/; ; HttpOnly", "correlation-id"=>"0A4DC804-62FD_AC11000F-0050_5E047DD5_8A0178-0015", "cache-control"=>"no-store, no-cache, no-store, must-revalidate", "pragma"=>"no-cache, no-cache", "content-type"=>"application/json;charset=UTF-8", "transfer-encoding"=>"chunked", "date"=>"Thu, 26 Dec 2019 09:31:01 GMT", "server"=>"Apache", "x-content-type-options"=>"nosniff", …Run Code Online (Sandbox Code Playgroud) 我决定使用新的Rspec 3(+ capybara/factory_girl)开始一个新项目,并且在学习新语法时遇到了麻烦.现在我有
user_pages_spec.rb(功能)
scenario "Signing Up" do
let(:submit) { "Sign up" }
scenario "With valid information" do
background do
fill_in "Username", with: "bbvoncrumb"
fill_in "Email", with: "bbvoncrumb@example.com"
fill_in "Password", with: "foobar123"
fill_in "Password confirmation", with: "foobar123"
end
scenario "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用未定义的方法'let'失败.和:
static_pages_spec.rb(控制器)
describe StaticPagesController do
describe "GET 'home'" do
it "returns http success" do
get :home
expect(response).to be_success
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用"未定义的方法'获取'.(这只是默认的控制器规范)