rspec2

How to set “programmatically”\“iteratively” each class object attribute to a value?

北战南征 提交于 2019-12-24 11:03:17
问题 I am using Ruby on Rails 3.0.9 and RSpec 2. I am trying to refactoring some spec file in the following way (in order to test with less code similar class object attribute values): [ :attribute_a, :attribute_b, :attribute_c ].each do |attr| before do # HERE I would like to set the "current" 'attr' related to the # class object instance 'attribute_< letter >' (read below for # more information) each time the iterator is called (note: all # following attributes are NOT attr_accesible - for that

how to run capybara commands once, then run some tests

吃可爱长大的小学妹 提交于 2019-12-24 08:55:51
问题 I have the given testing code: describe 'A new user', js: true do before do @new_user = Fabricate.build(:user) end it 'should sign up' do #login code visit '/' click_link 'Login' fill_in 'user[email]', :with => @new_user.email fill_in 'user[password]', :with => @new_user.password click_button 'Login now' #login code end page.should have_content("Hello #{@new_user.first_name}!") current_path.should == dashboard_path end it 'should receive a confirmation mail' do #same login code again visit '/

Rspec don't delete 2 specific tables

十年热恋 提交于 2019-12-24 03:07:17
问题 I am using Rspec for testing a rails application. I have 2 tables I imported data into (both the test and development database) The entire application is dependent on the tables data, meaning the entire functionality is matching, calculating and measuring data from this table and putting it into other tables. so, when testing, there's no point in deleting these table's data but Rspec is still deleting the data from them. my question is: how can I force Rspec not to delete data from these

rspec test using regular database not test database

家住魔仙堡 提交于 2019-12-24 01:43:41
问题 I am using Rspec, webrat, selenium rc for tests. I am trying to do integration test with selenium and rspec. I just looked in my development database and learned that my integration tests are using my development database and not my test database. How an I configure rails and rspec and selenium to use my test database. All my other tests seem to be using my test database. 回答1: Do you have a line like ENV["RAILS_ENV"] ||= 'test' in your spec_helper.rb? does it force the use of the test db if

How to login a user in RefineryCMS tests?

南笙酒味 提交于 2019-12-24 00:45:55
问题 I'm developing a custom controller in refineryCMS, that placed in the root of the app class ExchangeController < ApplicationController def exchange end end It works fine, but to have it tested I need to login a refinery user like this describe "Exchange action" do login_refinery_user it 'should return a 200' do get '/exchange' response.code.should == '200' end end But it just doesn't work :( (undefined local variable or method `login_refinery_user') Without calling that login method im

How do I use Capybara get, show, post, put in controller tests?

拟墨画扇 提交于 2019-12-23 18:25:22
问题 I'm just not sure what the exact way to word it is.. This tells me 'No response yet. Request a page first.' it "should list searches" do get 'index' page.should have_selector('tr#search-1') end Is it meant to be like this instead? it "should list searches" do get 'index' do page.should have_selector('tr#search-1') end end That way doesn't seem to actually test anything though. What's the correct way? 回答1: According to this, Capybara doesn't support PUT and DELETE requests with the default

Rails 3, too many ways to test?

喜欢而已 提交于 2019-12-23 16:53:40
问题 If you were just starting out in rails which path would you encourage new users to go down with regards to Testing . Anything I read about regarding Rails 3, tells me I should be using Rspec 2 . But Rspec comes with a whole whack of other things I need to learn like gem 'capybara' gem 'database_cleaner' gem 'cucumber-rails' gem 'cucumber' gem 'spork' gem 'launchy' And then one of my friends just told me that I should just stick to the testing framework that comes with rails, and maybe just

How to test upload with Carrierwave + FactoryGirl

為{幸葍}努か 提交于 2019-12-23 15:30:01
问题 I want to create some tests for my app and I have the following error: 1) User feeds ordering should order feeds by id desc Failure/Error: @post_1 = FactoryGirl.create(:post) ActiveRecord::AssociationTypeMismatch: Attachment(#87413420) expected, got Rack::Test::UploadedFile(#81956820) # ./spec/models/user_spec.rb:37:in `block (3 levels) in <top (required)>' This error is because I have this on my factories.rb file factory :post do title "Lorem Ipsum" description "Some random text goes here"

rspec testing association

无人久伴 提交于 2019-12-23 08:55:40
问题 I want to test that a staff member is associated with a company in my rspec controller tests. I would like to end up with this in my create action of the staff controller: staff.companies << current_company Where current_company is collected from a session variable. How do I write a test for this? I've got these models class Company < ActiveRecord::Base has_many :employees has_many :staff, :through => :employees end class Employee < ActiveRecord::Base belongs_to :company belongs_to :staff end

Rspec2 partial view gives nil:NilClass. Why?

爱⌒轻易说出口 提交于 2019-12-23 05:11:20
问题 I am trying to get going with development of view components with Rspec2 and Rails3. However, I make the following observation, and I don't understand what is going on, and how to fix this. In my spec I define: describe "main/index.html.erb" do it "displays a photo url in products partial" do assign(:designs, [stub_model(Design, :name => "test", :photo => "photo_url")]) render rendered.should contain("photo_url") end end When I run: rspec spec/view/main_spec.rb I get this error: 1) main/index