rspec3

Capybara::ElementNotFound: Unable to find file field “file”

邮差的信 提交于 2019-12-07 00:19:34
问题 I am testing file upload i.e CSV. In my code as well as browser HTML I found file field but while testing the capybara is unable to find the file field. I tried hard and different approaches but unable to fix the problem. Here partial look like this: #add_file_box %div.msg %h1.page-header = "Upload a CSV" %h4.title = form_tag dummy_path, multipart: true, class: "upload_csv" do = hidden_field_tag :dmp_id, @dmp.id .form-group .input-group %span.input-group-btn %span.btn.btn-primary.btn-file

Rspec to have(n).items undefined method

烈酒焚心 提交于 2019-12-06 16:43:12
问题 I'm trying to follow a guide on code.tuts and I keep getting an error. Here is my Library spec: require 'spec_helper' describe Library do before :all do lib_arr = [ Book.new("JavaScript: The Good Parts", "Douglas Crockford", :development), Book.new("Dont Make me Think", "Steve Krug", :usability), ] File.open "books.yml", "w" do |f| f.write YAML::dump lib_arr end end before :each do @lib = Library.new "books.yml" end describe "#new" do context "with no parameters" do it "has no book" do lib =

Find a newly created record in a controller test using RSpec 3 and Rails 4

丶灬走出姿态 提交于 2019-12-06 08:10:22
I'm doing a controller spec in Rails 4, and I'm wanting to test the attributes of a record created by a controller action. How do I find the newly created record? For example, what could I do instead of it 'Marks a new user as pending' do post :create, params # I don't want to use the following line user = User.last expect(user).to be_pending end The Rails guides only briefly talks about controller tests, where it mentions testing that Article.count changes by 1, but not how to get a new ActiveRecord model. The question Find the newest record in Rails 3 is about Rails 3. I'm reluctant to use

Rspec 3. undefined local variable or method `response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90>

非 Y 不嫁゛ 提交于 2019-12-06 07:53:56
I want to test API controller with rspec. So here is the simple piece of code: require 'rails_helper' describe "GET /api/config" do it 'routes GET to /api/config to Api::V1::ConfigsController#show' do get '/api/config.json' expect(response).to be_success end end But I've got an error: 1) Configs API GET /api/config routes GET to /api/config to Api::V1::ConfigsController#show Failure/Error: expect(response).to be_success NameError: undefined local variable or method `response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90> # ./spec/routing/api/v1/devise/configs_routing

How can I stub a controller helper method in a view spec with RSpec 3.4?

时光毁灭记忆、已成空白 提交于 2019-12-06 03:31:01
I'm testing a view with RSpec (3.4 on Rails 4.2.5). And I use the decent_exposure gem in my CRUD controller. decent_exposure makes it easy to define named methods that are made available to my views and which memoize the resultant values. But I don't understand how I can stub these methods in a view spec. I tried do it according to the RSpec documentation, but it raises an error. Why doesn't it work? How can I stub the method article in the view? My controller class Account::ArticlesController < Account::BaseController expose(:articles) { current_user.articles } expose(:article, attributes:

Capybara::ElementNotFound: Unable to find file field “file”

佐手、 提交于 2019-12-05 04:01:13
I am testing file upload i.e CSV. In my code as well as browser HTML I found file field but while testing the capybara is unable to find the file field. I tried hard and different approaches but unable to fix the problem. Here partial look like this: #add_file_box %div.msg %h1.page-header = "Upload a CSV" %h4.title = form_tag dummy_path, multipart: true, class: "upload_csv" do = hidden_field_tag :dmp_id, @dmp.id .form-group .input-group %span.input-group-btn %span.btn.btn-primary.btn-file Choose file = file_field_tag :file, style: 'line-height: normal', accept: "text/csv", class: "file_input"

Rspec to have(n).items undefined method

坚强是说给别人听的谎言 提交于 2019-12-04 22:20:38
I'm trying to follow a guide on code.tuts and I keep getting an error. Here is my Library spec: require 'spec_helper' describe Library do before :all do lib_arr = [ Book.new("JavaScript: The Good Parts", "Douglas Crockford", :development), Book.new("Dont Make me Think", "Steve Krug", :usability), ] File.open "books.yml", "w" do |f| f.write YAML::dump lib_arr end end before :each do @lib = Library.new "books.yml" end describe "#new" do context "with no parameters" do it "has no book" do lib = Library.new expect(lib).to have(0).books end end context "with a yaml file name parameters" do it "has

Rails/RSpec toggle cache for a single test

本小妞迷上赌 提交于 2019-12-04 05:02:17
So in my app I can disable the cache for all tests, which would be ideal, but apparently there are a number of legacy tests that rely on the cache being functional. Is there a way to enable the Rails cache for a single RSpec test? Something like: before(:each) do @cache_setting = Rails.cache.null_cache Rails.cache.null_cache = true end after(:each) do Rails.cache.null_cache = @cache_setting end it 'does not hit the cache' do ... end in spec_helper.rb RSpec.configure do |config| config.before(:example, disable_cache: true) do allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache:

RSpec: stubbing Rails.application.config value doesn't work when reopening classes?

老子叫甜甜 提交于 2019-12-03 11:57:53
I have an option defined in application config. My class I want to test is defined in a gem (not written by me). I want to reopen the class: Myclass.class_eval do if Rails.application.config.myoption=='value1' # some code def self.method1 end else # another code def self.method2 end end end I want to test this code using RSpec 3: # myclass_spec.rb require "rails_helper" RSpec.describe "My class" do allow(Rails.application.config).to receive(:myoption).and_return('value1') context 'in taxon' do it 'something' do expect(Myclass).to respond_to(:method1) end end end How to stub application config

RSpec matcher that checks collection to include item that satisfies lambda

送分小仙女□ 提交于 2019-12-02 04:06:18
I am a bit at a loss as to how to write a RSpec 3.2.x spec that checks wether a list contains at least one item that satisfies a condition. Here is an example: model = Invoice.new model.name = 'test' changes = model.changes expect(changes).to include { |x| x.key == 'name' && x.value == 'test' } There will be other (automated) changes in the changes list too so I don't want to verify that there is only one specific change and I also don't want to rely on ordering expect(changes.first)... so I basically need a way to specify that at least one change in the list satisfies the condition. I could