rspec

Testing Rake task with Rspec with Rails environment

删除回忆录丶 提交于 2019-12-20 17:28:52
问题 I'm trying to test a rake task and it uses an active record in it. require 'spec_helper' require 'rake' load File.join(Rails.root, 'lib', 'tasks', 'survey.rake') describe "survey rake tasks" do describe "survey:send_report" do it "should send a report" do Rake::Task['survey:send_report'].invoke end end end When I run this spec rspec spec/lib/survey_spec.rb , I get this error " RuntimeError: Don't know how to build task 'environment' How do I load the :enviroment task inside by example spec?

Is there a way to print javascript console.errors to the terminal with Rspec/Capybara/Selenium?

落爺英雄遲暮 提交于 2019-12-20 17:06:09
问题 When I run rspec, is it possible to have capybara/selenium report any javascript console.errors and other exceptions back to rspec? I have a whole bunch of tests failing, but my application is working when I manually test it. Without knowing the javascript errors that are likely blocking my single-page web app only during testing, it's really hard to figure out why the tests are failing. I've looked around and haven't really been able to find a solution to this. 回答1: I don't know if this will

Is there a way to print javascript console.errors to the terminal with Rspec/Capybara/Selenium?

大兔子大兔子 提交于 2019-12-20 17:05:08
问题 When I run rspec, is it possible to have capybara/selenium report any javascript console.errors and other exceptions back to rspec? I have a whole bunch of tests failing, but my application is working when I manually test it. Without knowing the javascript errors that are likely blocking my single-page web app only during testing, it's really hard to figure out why the tests are failing. I've looked around and haven't really been able to find a solution to this. 回答1: I don't know if this will

Set Chrome as Default Browser for RSpec/Capybara

青春壹個敷衍的年華 提交于 2019-12-20 16:37:23
问题 I'm having some trouble getting Chrome to work with RSpec/Capybara on Ubuntu 13.10 64-bit. By default it launches Firefox - we tried to change this a variety of ways, including: http://actsasblog.ca/2011/09/28/how-to-use-chrome-with-capybara/ /home/.../xxx_spec.rb:8:in `<top (required)>': undefined local variable or method `“chromedriver”' for main:Object (NameError) We also tried: require 'capybara/rspec' require 'rspec' require 'selenium-webdriver' Capybara.register_driver :selenium do |app

rspec testing has_many :through and after_save

前提是你 提交于 2019-12-20 14:36:31
问题 I have an (I think) relatively straightforward has_many :through relationship with a join table: class User < ActiveRecord::Base has_many :user_following_thing_relationships has_many :things, :through => :user_following_thing_relationships end class Thing < ActiveRecord::Base has_many :user_following_thing_relationships has_many :followers, :through => :user_following_thing_relationships, :source => :user end class UserFollowingThingRelationship < ActiveRecord::Base belongs_to :thing belongs

Running parallel selenium tests with capybara

天大地大妈咪最大 提交于 2019-12-20 13:17:07
问题 Background: I have a set of Capybara integration tests running against my Rails 3 Application. For the other parts of the test suite I'm using Rspec . I have a selenium 2.6.0 standalone server hub on my Mac OSX dev machine. java -jar selenium-server-standalone-2.6.0.jar -role hub I'm running several virtual machines each hooked up to the hub with a selenium node: java -jar selenium-server-standalone-2.6.0.jar -role webdriver -hub http://0.0.1.12:4444/grid/register port 5555 -browser

Can I run a Rails engine's specs from a real app which mounts it?

妖精的绣舞 提交于 2019-12-20 12:37:08
问题 I have a Rails Engine meant to provide some models and controllers to a larger project of ours. There's a pretty decent set of specs for the Engine, using a bunch of mocks and some full-scale models and controllers within the engine's dummy app to make sure the Engine is doing what it's supposed to and working with the larger application. However, even with all tests passing, I frequently find broken behavior when I update the engine in the larger application. If my tests are passing but the

Testing simple STI with FactoryGirl

无人久伴 提交于 2019-12-20 11:06:28
问题 I have got a class, that is the base of some other classes that specializes the behavior: class Task < ActiveRecord::Base attr_accessible :type, :name, :command validates_presence_of :type, :name, :command # some methods I would like to test end The class CounterTask inherits from Task class CounterTask < Task end This all works fine until I am trying to test the base class, since it must have a type. FactoryGirl.define do factory :task do sequence(:name) { |n| "name_#{n}" } sequence(:command

Do routing specs support redirect routes? [RSpec]

牧云@^-^@ 提交于 2019-12-20 11:06:05
问题 After digging fairly deeply on this issue, I've come to an impasse between my understanding of the documentation and my results. According to https://www.relishapp.com/rspec/rspec-rails/v/2-8/docs/routing-specs/route-to-matcher, we should be able to write the following: #rspec-rails (2.8.1) #rspec (>= 1.3.1) #rspec-core (~> 2.8.0) # routing spec require "spec_helper" describe BusinessUsersController do describe "routing" do it "routes to some external url" do get("/business_users/7/external

How to call an app helper method from an RSpec test in Rails?

耗尽温柔 提交于 2019-12-20 11:05:27
问题 The title is self explanatory. Everything I've tried led to a "undefined method". To clarify, I am not trying to test a helper method. I am trying to use a helper method in an integration test. 回答1: You just need to include the relevant helper module in your test to make the methods available: describe "foo" do include ActionView::Helpers it "does something with a helper method" do # use any helper methods here It's really as simple as that. 回答2: For anyone coming late to this question, it is