rspec

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

rspec stack level too deep

我怕爱的太早我们不能终老 提交于 2020-01-24 18:29:25
问题 When I run my model specs and controller specs separately, it's fine. When I run them together, I get a stack overflow, literally :) $ bundle exec rspec --fail-fast spec/models ........ Finished in 0.44274 seconds 8 examples, 0 failures $ bundle exec rspec --fail-fast spec/controllers .. Finished in 0.99339 seconds 2 examples, 0 failures $ bundle exec rspec --fail-fast spec F Failures: 1) HerpController derp derp example Failure/Error: Unable to find matching line from backtrace

rspec - how to check that allow_blank exists

不羁的心 提交于 2020-01-24 11:06:29
问题 I have a test for uniqueness which works: it { should validate_uniqueness_of(:name).case_insensitive } however when I try to do a similar test for name it fails it { should validate_presence_of(:name).allow_blank } I get this error: undefined method allow_blank'` 回答1: According to this list, there's no method in shoulda that can be chained to validate_presence_of that would support what you want to do. Have a look at the source code of the matcher here. However, there is another matcher you

rails tutorial expected css title with text to return something

好久不见. 提交于 2020-01-24 01:24:09
问题 I am working through the RoR tutorial at ruby.railstutorial.org and am currently on chapter 4. The tests aren't validating and I have no idea why. Top part of my spec file looks like this. The other methods all look identical to Help: describe "StaticPages" do let(:page_title) {"Ruby on Rails Tutorial Sample App"} let(:h1_test) {"should have the h1"} let(:title_test) {"should have the title"} describe "Home page" do |title_test, h1_test| it "#{h1_test} 'Sample App'" do visit '/static_pages

RSpec: difference between “should == …” and “should eql(…)”

余生长醉 提交于 2020-01-23 05:16:26
问题 In RSpec, what's the difference between using should == ... and should eql(...) ? I noticed that the RSpec documentation always uses eql , but == is less typing and easier to read. What am I missing? 回答1: It's rather simple, really: should == sends the == message to the test subject, should eql sends the eql? message to the test subject. In other words: the two different tests send two completely different messages which invoke two completely different methods and thus do two completely

RSpec: difference between “should == …” and “should eql(…)”

北城余情 提交于 2020-01-23 05:16:15
问题 In RSpec, what's the difference between using should == ... and should eql(...) ? I noticed that the RSpec documentation always uses eql , but == is less typing and easier to read. What am I missing? 回答1: It's rather simple, really: should == sends the == message to the test subject, should eql sends the eql? message to the test subject. In other words: the two different tests send two completely different messages which invoke two completely different methods and thus do two completely

WebMock simulate failing API (no internet, timeout ++)

北城余情 提交于 2020-01-23 04:37:15
问题 I am trying to simulate unexpected behaviour from a web api, such as not finding the server and timeouts, using webmock. What would be the best way to do this? All I can think of is to do something like this: stubbed_request = stub_request(:get, "#{host}/api/something.json"). with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}). to_return(:status => [500, "Internal Server Error"]) That should work for things like 404 etc., but how can I test timeouts ,

FactoryGirl creates user, but save point is released before test starts

瘦欲@ 提交于 2020-01-23 01:55:11
问题 I am running rspec tests for spec/requests/user_pages_specs: require 'spec_helper' describe "User pages" do subject { page } describe "home page" do before { visit root_path } it { should have_content('Sign up with Facebook') } it { should have_title(full_title('')) } end describe "profile page" do let(:user) { FactoryGirl.create(:user) } before { visit user_path(user.id) } it { should have_content(user.name) } it { should have_title(user.name) } end end As you can see, I am using FactoryGirl

Rspec Mocking: ActiveRecord::AssociationTypeMismatch

£可爱£侵袭症+ 提交于 2020-01-22 19:54:31
问题 I'm new to Rspec and trying to set up a test for a User Profile. Profile belongs_to User. Now, I have an API integration with a third party site that works through the User Model, but some of the information for that API link is contained in Profile, so I have an "after_update" filter on Profile that tells the parent user to save, which triggers an update of the API. I'm trying to write a test for this, and I'm getting an ActiveRecord::AssociationTypeMismatch. The reason is I'm using a mock