rspec-rails

How to find a variable with rspec tests using page.find

纵饮孤独 提交于 2020-03-15 11:49:42
问题 I have a test case, most of my other pages have at least one field that is just straight text and can be found using: page.find("tr", text: "What I filled in").find("a.tick").click This page all of the options are drop down selects, so how do I find a variable? The rest of the syntax looks like this: it "edits person job and redirects to index" do expect(p = FactoryGirl.create(:person)).to be_valid() expect(j = FactoryGirl.create(:job)).to be_valid() visit new_job_path select p.name, from:

How to find a variable with rspec tests using page.find

匆匆过客 提交于 2020-03-15 11:48:17
问题 I have a test case, most of my other pages have at least one field that is just straight text and can be found using: page.find("tr", text: "What I filled in").find("a.tick").click This page all of the options are drop down selects, so how do I find a variable? The rest of the syntax looks like this: it "edits person job and redirects to index" do expect(p = FactoryGirl.create(:person)).to be_valid() expect(j = FactoryGirl.create(:job)).to be_valid() visit new_job_path select p.name, from:

How to find a variable with rspec tests using page.find

我怕爱的太早我们不能终老 提交于 2020-03-15 11:45:59
问题 I have a test case, most of my other pages have at least one field that is just straight text and can be found using: page.find("tr", text: "What I filled in").find("a.tick").click This page all of the options are drop down selects, so how do I find a variable? The rest of the syntax looks like this: it "edits person job and redirects to index" do expect(p = FactoryGirl.create(:person)).to be_valid() expect(j = FactoryGirl.create(:job)).to be_valid() visit new_job_path select p.name, from:

How to reuse scenarios within different features with rspec + capybara

荒凉一梦 提交于 2020-02-01 03:42:24
问题 Say I have some scenarios that I want to test under different contexts, or "features". For example, I have scenarios which involve the user visiting certain pages and expecting certain ajax results. But, under different conditions, or "features", I need to perform different "background" tasks which change the state of the app. In this case I need to run the same scenarios over and over again to make sure that everything works with the different changes to the state of the app. Is there a way

testing routes with subdomain constraints using rspec

◇◆丶佛笑我妖孽 提交于 2020-01-29 04:54:20
问题 I'm having trouble getting my rspec routing tests working with a subdomain constraint. Specifically I have a route constraints :subdomain => "api" do resources :sign_ups, :only => [:create] end and (among others) a test it "does allow creation of sign ups" do {:post => "/sign_ups"}.should route_to( :controller => "sign_ups", :action => "create", ) end If I remove the subdomain constraint this test passes, but with it it fails. I have to tell rspec to use the subdomain but I'm at a loss as to

Show runtime for each rspec example

余生长醉 提交于 2020-01-29 03:18:52
问题 currently I'm running more than 1k examples and it's taking a long time to complete (more than 20 minutes!!! ). I'd like to identify which examples are the ones taking more time to complete, is there any way to run rspec and return the time each example takes to complete(individually)? I'm using rspec 1.3.0 and rspec-rails 1.2.3 回答1: You can use profiling to list your 10 slowest examples: spec -p spec/*/*_spec.rb --colour --format profile If you run this on a specific test suite you can get

Apipie receiving integer param as String

纵然是瞬间 提交于 2020-01-25 10:14:17
问题 I have the following RSpec test: it 'should not list alerts, since I do not have access to this model' do get :index, params: { model_id: @model2.id, workspace_id: @workspace.id }, as: :json expect(response).to have_http_status(:forbidden) end and it is failing because Apipie is complaining the workspace_id is a String when it is actually not, it is an Integer. I debugged the call, inspected @workspace and id is definitely an Integer. I'm seeing this issue now that I'm migrating the

Appending headers to Rspec controller tests

◇◆丶佛笑我妖孽 提交于 2020-01-22 09:25:40
问题 I'm trying to write out tests for a controller of mine that takes in requests from external services. So far this is my test: describe ApplyController do context 'when valid' do let(:parameters) do file = File.join File.dirname(__FILE__), '..', 'samples', 'Indeed.json' JSON.parse(File.read file) end let(:signature) { 'GC02UVj0d4bqa5peNFHdPQAZ2BI=' } subject(:response) { post :indeed, parameters, 'X-Indeed-Signature' => signature } it 'returns 200 ok if Request is valid' do expect(response

How can I determine the subject of an rspec controller test?

房东的猫 提交于 2020-01-15 04:51:11
问题 So I don't have a great reason for needing to know this other than curiosity - the BEST reason - but I'm not sure what's going on here. Background: I'm working through the RSpec book and updating the examples. On Chapter 24 - Rails Controllers there's a test for a messages controller. ## spec/controllers/messages_controller_spec.rb ## require 'spec_helper' describe MessagesController do describe "POST create" do let(:message) { mock_model(Message).as_null_object } before do Message.stub(:new)

Tests do not run when file changes with Guard and rspec on windows

隐身守侯 提交于 2020-01-10 04:54:08
问题 I've installed the guard-rspec gem for use in my rails application. When I start up guard from the command line via bundle exec guard , it runs my entire test suite the first time with no problem. However, any time I make any changes to a spec file or any watched files as specified in my Guardfile, Guard doesn't seem to recognize the changes and no tests are rerun. I even tried putting something every explicit in my Guardfile like this: watch("app/views/orders/new.html.erb") { "spec/requests