rspec

Having a default port when running tests in ruby on rails

断了今生、忘了曾经 提交于 2019-12-22 08:59:17
问题 Im trying to run my tests with rake spec Im using rspec,capybara with selenium as webdriver. The problem is when ever I try to run the specs It starts up the testing environment in a different port every time. I don't want this to happen as it messes up my Facebook login. How would I make the environment start in the same port every time. pls help! 回答1: Look in config/initializers/webservice.rb and try setting the config.port value to something...I'm not entirely sure this will actually do

How to test stdin for a CLI using rspec

旧巷老猫 提交于 2019-12-22 08:38:27
问题 I'm making a small Ruby program and can't figure out how to write RSpec specs that simulate multiple user command line inputs (the functionality itself works). I think this StackOverflow answer probably covers ground that is closest to where I am, but it's not quite what I need. I am using Thor for the command line interface, but I don't think this is an issue with anything in Thor. The program can read in commands either from a file or the command line, and I've been able to successfully

How to develop a Rails3 engine against a real app, using RSpec?

为君一笑 提交于 2019-12-22 08:28:39
问题 A lot has been written about engine development, and using a dummy app for testing. In our case we're developing an engine that is not a stand-alone entity, but has dependencies on a real Rails 3 application. We still want this code to live in an engine, and not become part of the app, because the engine's job is to import data from a legacy system that has its own tables and model mappings, and we want to eventually remove it again. The data mappings between the old legacy tables and the new

Factory Girl - has many associations

[亡魂溺海] 提交于 2019-12-22 08:11:54
问题 I'm using factory girl with rspec, here is what I have: factories.rb Factory.define :user do |f| f.sequence(:fname) { |n| "fname#{n}" } f.sequence(:lname) { |n| "lname#{n}" } f.sequence(:email) { |n| "email#{n}@google.com" } f.password "password" f.password_confirmation { |u| u.password } f.invitation_code "xxxxxxx" end Factory.define :group do |f| f.sequence(:name) { |n| "myGroup#{n}" } f.sequence(:private_email) { |n| "myGroup#{n}" } end Factory.define :permission do |f| f.role_id 1 end

database_cleaner is wiping my development database

泪湿孤枕 提交于 2019-12-22 07:02:40
问题 I have database-cleaner configured for my rails 4 application, Each time I run the test, I discovered that my database gets wiped out in both the test and development environment. My configurations are in rails_helper as follow: ENV["RAILS_ENV"] ||= 'test' # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'database_cleaner' Rails.env = "test" # Add

Testing CSV.generate with RSpec

大兔子大兔子 提交于 2019-12-22 06:59:54
问题 I have the following helper in a rails 3.1 project - I'm just wondering if there's a way to test that CSV.generate call. I'd love to say I have some sort of idea how to do it, but the truth is I don't even know where to start. Any ideas appreciated. require 'csv' module Admin::PurchasesHelper def csv_purchase_list columns = ['course', 'amount', 'first_name', 'last_name', 'contact_phone', 'contact_mobile', 'created_at'] CSV.generate(:col_sep => ";", :row_sep => "\r\n", :headers => true, :write

How to run Node.js and Ruby tests within one project on Travis CI

隐身守侯 提交于 2019-12-22 06:50:07
问题 I have a repo that contains multiple components, most of them in JavaScript (Node.js) and one written in Ruby (Ruby on Rails). I'd like to have one .travis.yml file that triggers one build that runs all the tests for each of the components. According to this Travis CI Google Group thread, there is no official support for this for now. My directory structure looks like this: . ├── buildserver ├── core ├── extensions ├── webapp ├── Vagrantfile ├── package.json ├── .travis.yml └── Makefile I

Rails: test a helper that needs access to the Rails environment (e.g. request.fullpath)

心已入冬 提交于 2019-12-22 06:39:31
问题 I have a helper that accesses request.fullpath . Within an isolated helper test, request is not available. What should I do? Can I somehow mock it or something like that? I'm using the newest versions of Rails and RSpec. Here's what my helper looks like: def item(*args, &block) # some code if request.fullpath == 'some-path' # do some stuff end end So the problematic code line is #4 where the helper needs access to the request object which isn't available in the helper spec. Thanks a lot for

“Rake spec” failing most tests, but “rails s” working fine on Diaspora source

佐手、 提交于 2019-12-22 05:16:11
问题 I've got source of Diaspora cloned and I've got a working local pod that seems to run without a hitch. But when I run $ rake spec some initial tests pass and then all of them start failing. Also, what I found interesting was that they fail at different points each time rake spec is run. They all fail with the error: An error occurred in an after hook ActiveRecord::StatementInvalid: PG::ConnectionBad: PQsocket() can't get socket descriptor: ROLLBACK occurred at /home/darshan/.rvm/gems/ruby-2.0

Rails 3 and rspec - select from select list

心已入冬 提交于 2019-12-22 05:11:35
问题 I want to select value from select list in RSpec . For example i have such data: <div class="control-group"> <label class="control-label" for="user_teacher_leader_attributes_teacher_id">Teacher names</label> <div class="controls"> <select id="user_teacher_leader_attributes_teacher_id" name="user[teacher_leader_attributes][teacher_id]"> <option value="1" selected="selected">Math teacher</option> <option value="2">Physics teacher</option> </div> </div> I want to select option Physics teacher