rspec

Upload file to an input area using FileApi

痞子三分冷 提交于 2019-12-24 16:19:25
问题 I'm using Capybara + RSpec and the capybara_webkit as driver. And a JS uploader with FileApi. I'm trying to upload three images here: <input type="file" name="image" multiple="" accept="image/*"> When I click on the "Select photos" button (on the browser), it opens the typical window where I can select 3 files from my computer . I'd like to know how to reproduce it on capybara, as when the photos selector opens, I don't have the control on it. I tried to add the pictures to my tests folder

Testing before_create method in rspec and rails 3

别等时光非礼了梦想. 提交于 2019-12-24 15:33:26
问题 I've looked into some tutes and all I saw were old posts on how to test before_create. Also it seems like they're all just testing that before_create was called i.e.: @user = User.new @user.should_receive(:method_name_called_by_before_create) @user.send(:before_create) (sometimes they just do @user.save) I want to actually test that my method worked and that it had assigned(and saved the variables) after creating the record. Here are my models: user.rb class User < ActiveRecord::Base has_one

Rails 3 - Validation for Time existence

谁说胖子不能爱 提交于 2019-12-24 15:13:28
问题 I have a model with a Time attribute. I want to check that time can not be empty (better choice probably would be to check that input is time but i have no ideas how to deal with that). I tried this validation: # id :integer not null, primary key # school_class_id :integer # meeting_time :time class Meeting < ActiveRecord::Base validates :meeting_time, :presence => { :message => "can't be empty!" } end Then i tried to check this in spec and this fails (empty time is ok but it should not be).

Rspec it{} evaluated uses last variable value

独自空忆成欢 提交于 2019-12-24 15:09:10
问题 I'm using Rspec to make some tests for my program. In a spec I instantiate the class once, and perform my tests on it using describes and contexts . I encountered something interesting, if the its seem to be evaluated at the end of the contexts. For example given the following classes and its associated spec: class Tmp def initialize @values = {} end def modify(new_value1, new_value2) @values = {:a => new_value1, :b => new_value2} end def get_values return @values end end describe Tmp do tmp

Testing rate-limited external API calls with VCR and RSpec

孤街醉人 提交于 2019-12-24 14:50:12
问题 In my Rails project, I'm using VCR and RSpec to test HTTP interactions against an external REST web service that only allows calls to it once per second . What this means so far is that I end up running my test suite until it fails due to a "number of calls exceeded" error from the web service. At that stage though, at least some cassettes get recorded, so I just continually run the test suite until eventually I get them all recorded and the suite can run using only cassettes (my default

RSpec + Capybara: How do I test a Bootstrap progress bar

ぃ、小莉子 提交于 2019-12-24 13:39:20
问题 I am testing a page that has a bootstrap progress bar using RSpec. How do I test the different Aria attributes in the Div? <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%"> </div> I appreciate any help you can provide. Thanks! 回答1: You can get the attribute values of an element using the [] method. For example: find('div.progress-bar')['aria-valuenow'] #=> "40" find('div.progress-bar')['aria-valuemax'

button_to form submittal working in browser but failing rspec/capybara test with routing error

蓝咒 提交于 2019-12-24 13:22:18
问题 I'm writing integration tests using rspec and capybara for a rails4 app that cover existing functionality (I was lazy when I first wrote the app). The following submit button works properly in the browser (Chrome) and redirects to a success page (as expected) <div class="actions"> <%= button_to "RSVP Now", new_event_attendee_path(f), :id => "open-contacts-dialog-btn", :class => "inbox-sf-add-btn tip", :style => "background:lightgreen" %> </div> But, the following test fails, describe "should

Test stay signed in with Rspec

 ̄綄美尐妖づ 提交于 2019-12-24 13:17:40
问题 I'm a bit stumped on how (and where) to write some rspec tests for the "stay signed in" functionality you see all over, including on the google login. The examples I found on the web weren't much help. Specifically I want to test these two scenarios. 1 a) user signs in with valid credentials without having clicked "stay signed in" b) user closes the browser, re-opens it and requests a protect page. The user should not see the protected page. The user should see the page asking them to signed

FactoryGirl: Building an object creates its associated object

…衆ロ難τιáo~ 提交于 2019-12-24 12:49:48
问题 I don't know if this is a bug with FactoryGirl or if it is something i am doing wrong I have two factory definitions factory :employee do name "name1" association :department end factory :department do name "department1" end I would expect the following to build both employee and department FactoryGirl.build(:employee, :name => "employee") But it builds the employee object and creates department in the database. I am sure it use to work in some older versions of FactoryGirl. I am using

*** RuntimeError Exception: ActionView::Helpers::ControllerHelper#response delegated to controller.response, but controller is nil

岁酱吖の 提交于 2019-12-24 12:25:28
问题 I'm running into an issue when I try to run my api specs for an endpoint. When I run the spec and check the response it says: *** RuntimeError Exception: ActionView::Helpers::ControllerHelper#response delegated to controller.response, but controller is nil: #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007faeb4852b08 I have a controller under controllers/api/v1/catalog_controller.rb class Api::V1::CatalogController < ApplicationController def search ...some stuff here... render