rspec2

Change Rubymine Rspec Color

a 夏天 提交于 2019-12-03 15:29:34
Im using Rspec for Testing, but CAN'T find how to change the grey color in to Red and Green. Im testing so much that -especially when an error occurs- im having a hard time reading the passed and failures. Any help would be nice :) I got it running by doing the following two things: In your run/debug configurations , enter -c in the Runner options field In your spec_helper.rb , add the following code: RSpec.configure do |config| config.tty = true end Additional info: http://rubyforge.org/pipermail/rspec-users/2011-January/019327.html Inside spec_helper.rb: RSpec.configure do |config| config

Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

人走茶凉 提交于 2019-12-03 12:13:16
问题 I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs before(:all) do ActiveSupport::TestCase.use_transactional_fixtures = false end after(:all) do ActiveSupport::TestCase.use_transactional_fixtures = true clean_engine_database end That now gives me the error: Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures =

How to ignore or skip a test method using RSpec?

爷,独闯天下 提交于 2019-12-03 11:37:32
问题 please guide how to disable one of the below test methods using RSpec. I am using Selenuim WebDriver + RSpec combinations to run tests. require 'rspec' require 'selenium-webdriver' describe 'Automation System' do before(:each) do ### end after(:each) do @driver.quit end it 'Test01' do #positive test case end it 'Test02' do #negative test case end end 回答1: You can use pending() or change it to xit or wrap assert in pending block for wait implementation: describe 'Automation System' do # some

Testing helpers in Rails 3 with Rspec 2 and Devise

非 Y 不嫁゛ 提交于 2019-12-03 10:44:50
My helper code looks like this (and works fine btw): module ProvidersHelper def call_to_review(provider) if user_signed_in? && review = Review.find_by_provider_id_and_user_id(provider.id, current_user.id) link_to "Edit Your Review", edit_provider_review_path(provider, review), :class => "call_to_review" else link_to "Review This Provider", new_provider_review_path(provider), :class => "call_to_review" end end end Unfortunately, this produces the following error when I run my tests: undefined method `user_signed_in?' for #<ActionView::Base:0x00000106314640> # ./app/helpers/providers_helper.rb:3

Does an RSpec2 matcher for matching Hashes exist?

假装没事ソ 提交于 2019-12-03 10:27:21
Note to future readers: think RSpec does not consider your Hashes equal? One might be an OrderedHash, but from the regular RSpec output you can't tell. This was the problem that prompted this post. Original question: Suppose I have a spec where I want to test that a method generates the appropriate Hash. it 'should generate the Hash correctly' do expected = {:foo => 1, 'baz' => 2} subject.some_method_that_should_generate_the_hash.should == expected end This often fails, because different Hashes with the same key-value pairs may return their pairs in a different ordered. Results look like:

CanCan load_and_authorize_resource triggers Forbidden Attributes

你离开我真会死。 提交于 2019-12-03 10:02:46
I have a standard RESTful controller that uses strong parameters. class UsersController < ApplicationController respond_to :html, :js def index @users = User.all end def show @user = User.find(params[:id]) end def new @user = User.new end def edit @user = User.find(params[:id]) end def create @user = User.new(safe_params) if @user.save redirect_to @user, notice: t('users.controller.create.success') else render :new end end def update @user = User.find(params[:id]) if @user.update_attributes(safe_params) redirect_to @user, notice: t('users.controller.update.success') else render :edit end end

Are there any good mutation testing tools for ruby 1.9 and RSpec2?

半世苍凉 提交于 2019-12-03 09:47:59
问题 I used to use Heckle, but it is incompatible with ruby 1.9 because of issues with ParseTree. I've looked for alternatives, but the only thing that looked promising was Chaser, and that did not have any clear documentation that I could use to see if I could make it work with RSpec. It seems to have Test::Unit dependencies. So - is anyone out there using any cool tools to really check the quality of your tests? Alternatively - are there any coverage tools that provide better than c0 coverage?

How to test scopes?

情到浓时终转凉″ 提交于 2019-12-03 09:40:41
问题 tried to find but with no success. Just wondering how could I test scopes in Rails 3. Could be using rspec, shoulda or just a test unit. Thanks. Actually, I trying this way, but it's not complete test since it's still need to put the order() method. The Scope: scope :recents_available, where(:available => true, :locked => false).order("created_at DESC") describe Job, ":recents_available" do it "should have the scope" do Job.should respond_to(:recents_available) end it "should include recents

mock Rails.env.development? using rspec

久未见 提交于 2019-12-03 07:38:16
问题 I am writing a unit test using rspec. I would like to mock Rails.env.develepment? to return true. How could I achieve this?. I tried this Rails.env.stub(:development?, nil).and_return(true) it throws this error activesupport-4.0.0/lib/active_support/string_inquirer.rb:22:in `method_missing': undefined method `any_instance' for "test":ActiveSupport::StringInquirer (NoMethodError) Update ruby version ruby-2.0.0-p353, rails 4.0.0, rspec 2.11 describe "welcome_signup" do let(:mail) { Notifier

rspec test result from csv.read mocking file

戏子无情 提交于 2019-12-03 05:05:52
I'm using ruby 1.9 and I'm trying to do BDD. My first test 'should read in the csv' works, but the second where I require a file object to be mocked doesn't. Here is my model spec: require 'spec_helper' describe Person do describe "Importing data" do let(:person) { Person.new } let(:data) { "title\tsurname\tfirstname\t\rtitle2\tsurname2\tfirstname2\t\r"} let(:result) {[["title","surname","firstname"],["title2","surname2","firstname2"]] } it "should read in the csv" do CSV.should_receive(:read). with("filename", :row_sep => "\r", :col_sep => "\t") person.import("filename") end it "should have