rspec

Ruby on Rails - Randomly failing RSpec tests

时间秒杀一切 提交于 2019-12-22 12:19:29
问题 Sorry for my stupid question. I added the external api to get response in order to check zipcode's validation. app/validators/zipcode_validator.rb class ZipcodeValidator < ActiveModel::Validator def validate(record) record.errors.add(:zipcode, :blank) if record.zipcode.blank? record.errors.add(:zipcode, :not_found) if WmsService.wms_delivery_dates(record.zipcode).nil? end end It works fine in real but failed randomly and took more time when I run rspec. What's the good solution for this

Unable to test should belong_to, missing id foreign key on Rails

戏子无情 提交于 2019-12-22 12:04:29
问题 Hello I have been looking for a way to test model relationship and stumble upon should gem shoulda (3.5.0) shoulda-context (1.2.1) shoulda-matchers (2.8.0) Unfortunatly I tried to test a simple example with rspec describe Region do it "should have a city" do should belong_to(:city) end end and I always get a message of Region should have a city Failure/Error: should belong_to(:city) Expected Region to have a belongs_to association called city (Region does not have a city_id foreign key.) # .

Unable to test should belong_to, missing id foreign key on Rails

爱⌒轻易说出口 提交于 2019-12-22 12:04:27
问题 Hello I have been looking for a way to test model relationship and stumble upon should gem shoulda (3.5.0) shoulda-context (1.2.1) shoulda-matchers (2.8.0) Unfortunatly I tried to test a simple example with rspec describe Region do it "should have a city" do should belong_to(:city) end end and I always get a message of Region should have a city Failure/Error: should belong_to(:city) Expected Region to have a belongs_to association called city (Region does not have a city_id foreign key.) # .

can I use multiple exclusion filters in rspec?

谁说我不能喝 提交于 2019-12-22 10:50:49
问题 In a _spec.rb file I'm setting up an exclusion filter something like: RSpec.configure do |config| # we need determine this once at the very front # and the result be available in the instance server_success = server1_available? config.exclusion_filter = { :svr1 => lambda {|what| case what when :available !server_success end } } end and then later in the file I do describe :get_items_by_client, :svr1 => :available do to prevent test execution if the server isn't available. This all works fine

Rpsec tests failed with 'rspec' but not with 'rspec path_of_the_file'

不羁的心 提交于 2019-12-22 10:13:12
问题 If I run this command "rspec ./spec/requests/api/v1/password_reset_request_spec.rb" all the test inside this file pass. However when I run "rspec" I've a faillure on the tests inside this file. 1) /api/v1/password_reset #request when the email match with a runner when there is no request pending create a token for reset the password Failure/Error: post("/api/v1/password_reset/request", @params) NoMethodError: undefined method `reset_password' for RunnerMailer:Class # ./app/services/password

Rails + Rspec + Rack + Session testing

你。 提交于 2019-12-22 09:48:03
问题 Gemfile file: 'rack', '~> 1.6.0' I am having little trouble in passing the session variables from rspec tests to the Rack middleware. I have gone through many articles on internet but there is no solution which can help me to understand. So basically i want to be able to do this in my middleware class req = Rack::Request.new(env) req.session[:token] But currently req.session[:token] comes as empty from my rspec. How can I set session in my R spec class so that i can test different scenario's

Rails: RSpec - undefined method `cookie_jar' for nil:NilClass

孤者浪人 提交于 2019-12-22 09:47:02
问题 Rails newbie. Trying to follow Michael Hartl's tutorial. Stuck trying to add a helper method to simulate log in an RSpec test: describe "when the a user has logged in and attempts to visit the page" do let(:user) { FactoryGirl.create :user } before do log_in user end it "should redirect the user to next page" do specify { response.should redirect_to loggedin_path } end end In my spec/support/utilities.rb: def log_in user visit root_path fill_in "Email", with: user.email fill_in "Password",

Rspec test for destroy if no delete link

烈酒焚心 提交于 2019-12-22 09:36:02
问题 I'm going through the latest rails tutorial on railstutorial.org and I am stuck on a certain exercise (#8 on http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#sec:updating_deleting_exercises). You have to write a rspec/capybara test to make sure the admin can't delete themself. I have the implementation working, but can't get the test to work right. Here is my code. I found similar questions here: Ruby on Rails syntax and https://getsatisfaction.com/railstutorial

RSpec+Capybara request specs w/ JS not working

一曲冷凌霜 提交于 2019-12-22 09:32:55
问题 I cannot get request specs working when using Javascript. My specs pass if I run them without Javascript (the page is built to work with or without JS). Specifically, the specs fail when I do assertions like Post.should have(1).record . Capybara just doesn't pick up the records from the DB, and the database is not cleaned between runs. I've tried using DatabaseCleaner with transactional fixtures disabled - the common approach to this, I guess. No dice. I've also tried (and, would ideally

Adding custom directories (source and spec) to autotest in a Rails 3 project

坚强是说给别人听的谎言 提交于 2019-12-22 09:26:55
问题 I have a Rails 3 app that uses RSpec2 as my testing framework, and I'm able to use autotest to watch my model and spec directories for changes and re-run my spec suite when files change. I'd like to add a directory with some custom classes in it (RAILS_ROOT/lib/some_project/lib/ .rb) and their corresponding specs (RAILS_ROOT/spec/some_project/ _spec.rb) so that autotest will automatically pick up changes to all of those files and re-run as needed. How do I get autotest to watch these files in