rspec

Difference between factory_girl and factory_girl_rails Ruby Gems

北慕城南 提交于 2020-01-03 05:18:31
问题 Is there a difference between factory_girl and factory_girl_rails Ruby Gems? I have a recurring problem with an error in RSpec Testing: "uninitialized constant FactoryGirl (NameError)". Somebody told me that there is a difference between the two (this is really confusing) and one needs the other to work or something along those lines? My spec_helper file has both: require 'factory_girl' require 'factory_girl_rails' My Gemfile has: gem 'factory_girl_rails' Here is the full error: uninitialized

rails rspec No route matches [duplicate]

给你一囗甜甜゛ 提交于 2020-01-03 05:10:08
问题 This question already has answers here : No route found in rspec test for an existing route (3 answers) Closed 4 years ago . I'm trying to test my routes (they work fine for real requests) and get this error: ActionController::UrlGenerationError: No route matches {:action=>"api/login", :controller=>"login", :email=>"a@a.com", :password=>"super_secure"} I've looked at a bunch of similar questions but could not find a precise answer for my problem. My route is: Rails.application.routes.draw do

Rails/RSpec - writing tests for original helper methods

筅森魡賤 提交于 2020-01-03 02:36:05
问题 I'm on the chapter 5 exercises for Michael Hartl's Rails Tutorial and am trying to wrap my head around how Rails/Rspec is testing a helper method full_title in app/helpers/application_helper.rb . All of my tests are in spec/requests/static_pages_spec.rb and within them, I'm calling full_title to cut down on code bloat. So, in order to test the original full_title I create a test in spec/helpers/application_helpers_spec.rb and include it via spec/support/utilities.rb . The code is passing, but

How to reuse code in Capybara

爱⌒轻易说出口 提交于 2020-01-02 11:29:09
问题 I have a bunch of codes with repeating structures in a feature test in Rails. I would like to dry up my spec by reusing the structure. Any suggestions? An example is: feature "Search page" subject { page } it "should display results" # do something within "#A" do should have_content("James") end within "#B" do should have_content("October 2014") end # do something else # code with similar structure within "#A" do should have_content("Amy") end within "#B" do should have_content("May 2011")

How to adjust Capybara finders on a site using css-modules?

浪子不回头ぞ 提交于 2020-01-02 07:10:24
问题 In our automated tests, a typical line in our code might look something like: find('.edit-icon').click We're on our way to using css-modules in our project and I've been warned that class names may change dramatically. A pretty zany example is this site that uses emojis in its class names (when you inspect the page): css modules by Glenn Maddern How might I best prepare for a change this drastic? I imagine many of our specs breaking, but I am a little worried about being unable to write tests

rspec view stubs and partials

不打扰是莪最后的温柔 提交于 2020-01-02 05:43:07
问题 I'm testing a view with RSpec (2.12 on Rails 3.2.8). I'm using CanCan to conditionally display certain elements on a page. This requires a controller method 'current_user'. In some of my specs I've been able to stub out current_user, eg. controller.stub(:current_user).and_return(etc) or view.stub.etc . This works for some of my specs. But I've got a couple where it's not working and I don't understand why. The two specs where it's not working test a view, which calls down into a partial, and

How to Populate Lookup tables in Testing (Rails)

孤街醉人 提交于 2020-01-02 05:06:10
问题 I am using Cucumber, Rspec, and Factory Girl for the testing of my Rails Application. But I have several lookup tables that contain mostly static data. So I'm trying to figure out the best way to populate these when testing. Doing them individually in FactoryGirl seems tedious and I'd like to stay away from Fixtures. For development and production, I populate them in my seeds.rb file. Thanks! 回答1: Use Factory Girl .sequence, Populator and Faker and you'll never run out of lab rats! Factory

Testing a Class inside of a Module with RSpec

Deadly 提交于 2020-01-02 04:34:32
问题 So, I have a module in my ruby code which looks something like this: module MathStuff class Integer def least_factor # implementation code end end end and I have some RSpec tests in which I would like to test that my Integer#least_factor method works as expected. we'll say that the tests are in the same file for simplicity. The tests look something like this: describe MathStuff do describe '#least_factor' do it 'returns the least prime factor' do expect(50.least_factor).to eq 2 end end end

Invalidate Sprockets cache during RSpec automated test

流过昼夜 提交于 2020-01-02 04:11:31
问题 In my Rails application, I have a .js.erb file that has a variable which gets dynamically set based on some Ruby code. var myTimer = <%= MyApp.config.timeout_time * 1000 %>; The app works fine, but I'm having a problem in some automated tests. The problem occurs in an RSpec feature test that works with this JavaScript. My spec file has a number of tests that change the ruby MyApp.config.timeout_time time on the fly to test out different scenarios. In my spec file, the first example passes,

Rspec 3 Deprecation Warning: Filtering by an example_group subhash is deprecated. Use the subhash to filter directly instead

喜欢而已 提交于 2020-01-02 03:10:07
问题 When running my Rspec version 3 tests, I get the following deprecation warnings: Filtering by an :example_group subhash is deprecated. Use the subhash to filter directly instead. Called from /path/to/file.rb:6:in `block in '. Filtering by an :example_group subhash is deprecated. Use the subhash to filter directly instead. Called from /path/to/file.rb:8:in `block in '. From path/to/file.rb: RSpec.configure do |config| module MyCodeHelpers # end config.include MyCodeHelpers, example_group: {