rspec

Getting Rspec + autotest working on windows

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 13:59:15
问题 I have installed growl + rspec + autotest on my windows 7 machine. From the command prompt, when I type 'rspec spec/' it doesn't work. The tests will only run if I use 'rake spec/' + 'autotest'. Also, I am running these tests: http://railstutorial.org/chapters/static-pages#code:default_pages_controller_spec (i.e. very, very trivial) and they are taking 8.11 seconds. They also fail when I run them - even though they don't in the example. I have done everything the tutorial told me, the problem

Rspec+Capybara optionally change JS driver

梦想的初衷 提交于 2020-01-03 13:55:09
问题 I use poltergeist/phantomjs for CI, but I want to be able to optionally change the JS driver to selenium to watch my test runs locally. Ideally I'd like to have a command line flag for this- default poltergeist, but be able to run rspec --driver=selenium (or something similar) Any ideas? 回答1: Never ended up finding an answer for this, so here's the hacky solution I came up with: The only thing I found that I could reliably change was the tagging system. So I call using -t visual tag and then

How to resolve RSpec's deprecation warning about the new expect syntax?

六眼飞鱼酱① 提交于 2020-01-03 10:18:29
问题 When I run this RSpec example, it passes but I'm getting a deprecation warning. context "should have valid detail for signup" do it "should give error for invalid confirm password" do find("#usernamesignup").set("Any_name") find("#mobile_number").set("1234567890") find("#emailsignup").set("mymail@yopmail.com") find("#passwordsignup").set("12345678") find("#passwordsignup_confirm").set("") find(".signin").click sleep 2 page.should have_content "Confirm Password Does not Match" end end Here is

Custom assert message for multiple expect statements within match

旧街凉风 提交于 2020-01-03 09:28:22
问题 I have written a custom match method in Rspec that matches an object against a hash. What I am trying to do is set custom failure messages for each line of the expect . describe "/cars" do car = FactoryGirl.create(:car, name: 'Alpha') describe car do it "displays single items" do get cars_path parsed_response = JSON.parse(response.body) record_hash = parsed_response['cars'][0] is_expected.to be_a_car_match_of(record_hash) end end end RSpec::Matchers.define :be_a_car_match_of do |hash| match

What is the difference between 'env' and 'request.env' in Rails Controller?

醉酒当歌 提交于 2020-01-03 08:14:09
问题 I'm using rspec to write test for my application. In order to authorization I'm sending token in header: request.headers['token'] = '000000099' get :index In controller side I can read this value by request.env["HTTP_TOKEN"] but env["HTTP_TOKEN"] is empty. What is the difference between them and how can I set env instead of request.env ? 回答1: request.env is a ruby array that contains information about a visiting user’s and server environments. request.env is the standard object that's being

stub random value in rspec with secure_random

蹲街弑〆低调 提交于 2020-01-03 08:09:06
问题 I am trying to write specs for my gem, which generates otp and saves it in db. Now i am writing specs for it. so basically i have three methods generate_otp! , regenerate_otp! , verify_otp(otp) . what generate_otp! does is it calls a method generate_otp which contains three variables otp_code - basically a random value generated using secure_random otp_verified - a boolean value to set the status whether otp is verified or not otp_expiry_time - sets expiry time for otp which can be set by

How can this destroy action be tested with RSpec?

强颜欢笑 提交于 2020-01-03 08:07:46
问题 In my Rails app, if a user wants to delete his own account he will first have to enter his password in my terminate view: <%= form_for @user, :method => :delete do |f| %> <%= f.label :password %><br/> <%= f.password_field :password %> <%= f.submit %> <% end %> This is my UsersController : def terminate @user = User.find(params[:id]) @title = "Terminate your account" end def destroy if @user.authenticate(params[:user][:password]) @user.destroy flash[:success] = "Your account was terminated."

How to get rspec to not show db queries and just dots with rails_12factor?

强颜欢笑 提交于 2020-01-03 07:36:29
问题 ruby: 2.0 rails: 3.2.17 rspec: 2.14.8 Database: mysql rspec spec used to just output the dots. I was getting a deprecation warning when I pushed to Heroku and recently added the rails_12factor gem to get around it. Now however I get this verbose db output for each transaction when running specs locally. That is a great option when I need it otherwise it is a lot of unneeded and distracting output. So I would like an option that will use it for Heroku but not locally. Note this is not

RSpec vs. Shoulda?

烈酒焚心 提交于 2020-01-03 07:26:09
问题 I am new to the unit testing scene; I have only been using unit tests for about 2 months now. When I unit test in Ruby I currently follow the TDD style and use Test::Unit::TestCase. I have also read about RSpec and how it follows the BDD methodology. I also have read about Shoulda which is a in between the two frameworks. My question is, which framework should I devote my time to RSpec or Shoulda, or should I stick with Test::Unit::TestCase? Any opinions on the subject are appreciated. 回答1:

How to store dynamic value and reuse in Webdriver Ruby test

拈花ヽ惹草 提交于 2020-01-03 07:16:08
问题 I'm writing a ruby webdriver test that needs to store a dynamic value such as an order ID to use later on in the text. I think I need to extract the value from the string and then store it as a variable to call for future use. The string looks like this and I just need to extract/store the numeric value. <span class="receiptNum hidden-xs">Receipt #: 12303430</span> Any tips or examples on how to extract that value and create a variable for future use would be great! 回答1: To extract the text