rspec

Testing devise views with rspec

◇◆丶佛笑我妖孽 提交于 2019-12-22 03:47:22
问题 I have generated Devise's views running rails g devise:views and would now like to test them. This is what I have come up with: require 'spec_helper' describe "devise/sessions/new" do before do render end it "renders the form to log in" do rendered.should have_selector("form", action: user_session_path, method: :post) do |form| end end end For the render statement it gives me undefined local variable or method 'resource' . After googling around I found that I should add @user.should_receive(

What are the options to Capybara's have_selector?

孤人 提交于 2019-12-22 03:43:32
问题 I got this error in RSpec. Are there any docs for have_selector that explain each key in the options hash and what exactly it does? invalid keys :content, should be one of :text, :visible, :between, :count, :maximum, :minimum, :exact, :match, :wait 回答1: capybara provides this method to rspec. capybara's docs don't make it easy to find the answer to your question, so let's follow the source: have_selector is in Capybara::RSpecMatchers . It delegates to the nested class HaveSelector , which

SimpleCov calculate 0% coverage for user model

拥有回忆 提交于 2019-12-22 02:04:09
问题 I decided to try using simplecov gem. And I think it's cool tool, but I have one problem: I have model User and I have user_spec.rb which contains test cases, but simplecov shows 0% coverage of this model. And It shows 100% coverage for other models, and It's true. I don't understand what's trouble with User model. class User < ActiveRecord::Base extend Enumerize # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database

rubyMine 'Unable to attach test reporter to test framework'

懵懂的女人 提交于 2019-12-22 02:03:07
问题 rubyMine 'MiniTest framework was detected' error when running all model tests. I can run all model tests at the regular command line. e.g. rake spec:models When I use rubyMine: I can run one model test ok. However when I try to run all tests in model I get MiniTest framework was detected. It is a limited version of original Test::Unit framework. RubyMine/IDEA Ruby plugin test runner requires full-featured version of the framework, otherwise default console tests reporter will be used instead.

mocking an error/exception in rspec (not just its type)

て烟熏妆下的殇ゞ 提交于 2019-12-22 02:02:10
问题 I have a block of code like this: def some_method begin do_some_stuff rescue WWW::Mechanize::ResponseCodeError => e if e.response_code.to_i == 503 handle_the_situation end end end I want to test what's going on in that if e.response_code.to_i == 503 section. I can mock do_some_stuff to throw the right type of exception: whatever.should_receive(:do_some_stuff).and_raise(WWW::Mechanize::ResponseCodeError) but how do I mock the error object itself to return 503 when it receives "response_code"?

FactoryGirl: Factory not registered

旧时模样 提交于 2019-12-22 01:38:17
问题 I work on a project with a structure like: projects/warehouse/core projects/warehouse/products/bottles projects/warehouse/products/boxes In this project, the application logic, gems, etc. are all in the core application. I have boxes set up for rspec like such: projects/warehouse/products/boxes/spec /factories /models The factories directory contains cubics.rb : FactoryGirl.define do factory :cubic id 1 dimension 12 end end The models directory contains cubic_spec.rb : require 'spec_helper'

Capybara not finding meta tags

拜拜、爱过 提交于 2019-12-22 01:34:21
问题 Capybara 2.1.0 doesn't seem to find any meta tags: (rdb:1) p page.find 'meta' *** Capybara::ElementNotFound Exception: Unable to find css "meta" even when they appear in page.source : (rdb:1) p page.source "<!doctype html>\n<html>\n<head>\n<title>MyTitle</title>\n<meta charset='utf-8'>\n<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>\n<meta content='width=device-width, initial-scale=1' name='viewport'>\n<meta name='description'>\n\n..." 回答1: The solution was to use :visible =>

Cucumber and RSpec testing with zeus: Postgres is being accessed by other users

ぐ巨炮叔叔 提交于 2019-12-22 01:17:40
问题 In my Rails 3.2.13 app, I'm using Zeus. In the test environment I use PostgreSQL. When I run Cucumber and then RSpec (or the other way around), 9 out of 10 times I get the message: PG::Error: ERROR: database "bp_test" is being accessed by other users DETAIL: There are 1 other session(s) using the database. : DROP DATABASE IF EXISTS "bp_test" Tasks: TOP => db:test:load => db:test:purge (See full trace by running task with --trace) It takes a whole non-deterministic circus of trying to kill

have_tag vs. have_selector

我只是一个虾纸丫 提交于 2019-12-21 22:31:17
问题 I've been using have_selector with RSpec (version 2.0.1) successfully. I recently found documentation on have_tag ... with_tag ... associated with RSpec 1.3.2 and would like to use it, but RSpec gives me the error: undefined method `has_tag?' for #<ActionController::TestResponse:0x105584e80> on the following lines: response.should have_tag("div.breadcrumbs select") do with_tag(:option, :value => @brands.name) with_tag(:option, :value => @marketsize.name) end I've tried the same syntax

Capybara visit method is not working

核能气质少年 提交于 2019-12-21 17:34:59
问题 I'm not sure what's going on, but I can't get simple tests to work because Capybara's visit method is not working for me. I've been trying to finish this railscast on testing. Once I get to the point where Capybara needs to visit the login page the test fails because it's only able to visit my root_url. Here's what the failure looks like. Note that it's failing because it can't even visit the login page. It's getting stuck on the homepage: Running: spec/requests/password_resets_spec.rb