Search Results

Search found 260 results on 11 pages for 'rspec'.

Page 8/11 | < Previous Page | 4 5 6 7 8 9 10 11  | Next Page >

  • Regex issue with comma's telling me there are 6 args, instead of intended 4

    - by Azher
    I have a scenario outline table that looks like the following: Scenario Outline: Verify Full ad details Given I am on the xxx classified home page And I have entered <headline> in the search field & clicked on search When I click on full details Then I should see <headline> <year> <mileage> <price> displaying correctly and successfully Examples: |headline |year |mileage |price | |alfa romeo 166 |2005 |73,000 |6,990 | When I run my scenario it spits out that I have 6 args. But what I thought, I should only have 4 args: headline, year, mileage and price. I am thinking that it is taking the comma's and what is before and after it as two seperate args. Is there any way that I can make cucumber think that there are only 4 args with the example below? I have looked at messing around with regex but I dont seem to be getting anywhere. Any help would be greatly appreciated.

    Read the article

  • Factory Girl sequence fails under autospec

    - by John
    I have this Factory: Factory.define :email_address do |e| e.sequence(:address) { |n| "factory_#{n}@example.com" } e.validated true end When I run my specs with rake spec, it works fine. When I run autospec, it fails right away, claiming that the email address is being used twice in two different objects (there is a validation which restricts this). Why is it behaving differently under autospec? Thanks, John

    Read the article

  • A simple factory_girl question

    - by gmile
    I have two factories (post_factory.rb, comment_factory.rb) in separate files. I'd like to create a bit complex factory, which will create a post with associated comments for me. I created a third file, called complex_factory.rb, and wrote the following code: Factory.define :post_with_comments, :parent => :post do |post| post.after_create { |p| Factory(:user_last_state, :post => p) } end But rake spec raises an error, stating that the file is unaware of post and comment factories. At the very next moment, I naïvely wrote requires at the top: require "post_factory.rb" require "comment_factory.rb" But that didn't gave any proper result. Maybe this requires actually looking the wrong direction? Or they pretty much don't matter (as registering factories for visibility might be more complex that I assume). Am I missing something? Any ideas?

    Read the article

  • Rails: How to test state_machine?

    - by petRUShka
    Please, help me. I'm confused. I know how to write state-driven behavior of model, but I don't know what should I write in specs... My model.rb file look class Ratification < ActiveRecord::Base belongs_to :user attr_protected :status_events state_machine :status, :initial => :boss do state :boss state :owner state :declarant state :done event :approve do transition :boss => :owner, :owner => :done end event :divert do transition [:boss, :owner] => :declarant end event :repeat do transition :declarant => :boss end end end I use state_machine gem. Please, show me the course.

    Read the article

  • Having difficulties in ending Michael Hartl's tutorial. Help?

    - by konzepz
    Following Michael Hartl's (amazing) Ruby on Rails Tutorial, on the final section, I get the following errors: 1) User micropost associations status feed should include the microposts of followed users Failure/Error: @user.feed.should include(mp3) expected [#<Micropost id: 2, content: "Foo bar", user_id: 1, created_at: "2011-01-12 21:22:41", updated_at: "2011-01-12 22:22:41">, #<Micropost id: 1, content: "Foo bar", user_id: 1, created_at: "2011-01-11 22:22:41", updated_at: "2011-01-12 22:22:41">] to include #<Micropost id: 3, content: "Foo bar", user_id: 2, created_at: "2011-01-12 22:22:41", updated_at: "2011-01-12 22:22:41"> Diff: @@ -1,2 +1,2 @@ -#<Micropost id: 3, content: "Foo bar", user_id: 2, created_at: "2011-01-12 22:22:41", updated_at: "2011-01-12 22:22:41"> +[#<Micropost id: 2, content: "Foo bar", user_id: 1, created_at: "2011-01-12 21:22:41", updated_at: "2011-01-12 22:22:41">, #<Micropost id: 1, content: "Foo bar", user_id: 1, created_at: "2011-01-11 22:22:41", updated_at: "2011-01-12 22:22:41">] # ./spec/models/user_spec.rb:214 2) Micropost from_users_followed_by should include the followed user's microposts Failure/Error: Micropost.from_users_followed_by(@user).should include(@other_post) expected [#<Micropost id: 1, content: "foo", user_id: 1, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46">] to include #<Micropost id: 2, content: "bar", user_id: 2, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46"> Diff: @@ -1,2 +1,2 @@ -#<Micropost id: 2, content: "bar", user_id: 2, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46"> +[#<Micropost id: 1, content: "foo", user_id: 1, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46">] # ./spec/models/micropost_spec.rb:75 Finished in 9.18 seconds 153 examples, 2 failures Seems like mp3 is not included in the feed. Any ideas on how to fix it? Or where to look for possible errors in the code? I compared the files with Hartl's original code; seems exact. Thanks.

    Read the article

  • How can I get a rails server to use the same databse that cucumber uses during a test?

    - by James
    The cucumber test first makes an entry in the database and posts a form to a second server. This second server does some processing in background and then hits the first app (where the test is being run) with some data that the cucumber test needs to know about. I've tried running the main server via script/server and script/server -e test while the cucumber test is running, but I can't seem to force the server to use the same database that cucumber is using when it runs its step definitions. That is, when the second server pushes some data to a controller in the main server, the main server doesn't know about any entries that cucumber has made in the database. How can I get cucumber and the main server to use the same database?

    Read the article

  • No route matches error with application_controller spec

    - by Eric M.
    I have an application_controller spec that is failing since I removed the controller/action route from routes.rb. I get the following error: No route matches {:controller=>"application", :action=>"index"} I had many tests fail in the same way, but was able to fix them by including the correct parameters in the get call. So for instance, if I wanted to get the standard show route for posts in my spec, I had to change get :show to get :show, :id => '1' Unfortunately, I'm not sure now what to pass along for the application controller specs. I've included my test below. describe ApplicationController do it "should find the latest published posts and assign them for the view" do Post.should_receive(:latest).and_return(@posts) get :index assigns[:posts].should == @posts end it "should find the latest approved comments and assign them for the view" do Comment.should_receive(:latest).and_return(@comments) get :index assigns[:comments].should == @comments end end

    Read the article

  • How do I get access to object being described?

    - by Bill T
    If I have an example such as the following: describe "A flux capacitor" do it "should flux a lot" do # how can I access the string object "A flux capacitor" in here??? ... end end How can I access the described string object "A flux capacitor"? I've tried a few permutations of 'described_type' and 'described_class' Such as: self.described_type.to_s But these always return nothing. What am I doing wrong? Thanks, -Bill

    Read the article

  • How can I spec out an authlogic sessions controller using using a stub?

    - by Dave
    I want to test my User Session Controller testing that a user session is first built then saved. My UserSession class looks like this: class UserSession < Authlogic::Session::Base end The create method of my UserSessionsController looks like this: def create @user_session = UserSession.new(params[:user_session]) if @user_session.save flash[:notice] = "Successfully logged in." redirect_back_or_default administer_home_page_url else render :new end end and my controller spec looks like this: describe UserSessionsController do it "should build a new user session" do UserSession.stub!(:new).with(:email, :password) UserSession.should_receive(:new).with(:email => "[email protected]", :password => "foobar") post :create, :user_session => { :email => "[email protected]", :password => "foobar" } end end I stub out the new method but I still get the following error when I run the test: Spec::Mocks::MockExpectationError in 'UserSessionsController should build a new user session' <UserSession (class)> received :new with unexpected arguments expected: ({:password=>"foobar", :email=>"[email protected]"}) got: ({:priority_record=>nil}, nil) It's although the new method is being called on UserSession before my controller code is getting called. Calling activate_authlogic makes no difference.

    Read the article

  • Is there a way to undo Mocha stubbing of any_instance?

    - by Steve Weet
    Within my controller specs I am stubbing out valid? for some routing tests, (based on Ryan Bates nifty_scaffold) as follows :- it "create action should render new template when model is invalid" do Company.any_instance.stubs(:valid?).returns(false) post :create response.should render_template(:new) end This is fine when I test the controllers in isolation. I also have the following in my model spec it "is valid with valid attributes" do @company.should be_valid end Again this works fine when tested in isolation. The problem comes if I run spec for both models and controllers. The model test always fails as the valid? method has been stubbed out. Is there a way for me to remove the stubbing of any_instance when the controller test is torn down. I have got around the problem by running the tests in reverse alphabetic sequence to ensure the model tests run before the controllers but I really don't like my tests being sequence dependant.

    Read the article

  • Why am I getting the error "undefined local variable or method `assigns'"?

    - by Jason
    I might be missing something basic here, but I'm stumped on this error: model code: class CachedStat < ActiveRecord::Base def self.create_stats_days_ago(days_ago, human_id) d = Date.today - days_ago.day @prs = PageRequest.find(:all, :conditions => [ "owner_type = 'Human' and owner_id = ? and created_at = ?", human_id, d] ) end end spec code: it "should create stats for the specified number of days in the past" do CachedStat.create_stats_days_ago(1, Human.first.id) assigns[:prs].should eql("foo") end The error is: undefined local variable or method `assigns' for #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x2fbac28> I feel like I'm overlooking something obvious but it's invisible to me. Any suggestions? Thanks very much! -Jason

    Read the article

  • How to create factories with attr_accesible?

    - by regedarek
    How to deal with factories and attr_accessible? My example: # model class SomeModel attr_accessible :name, full_name, other_name end #spec require 'spec_helper' describe "test" do it do create(:some_model, name: "test name", user: User.first) #factory end end #error ruby(17122,0x12a055000) malloc: *** error for object 0x8: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug I think the error is because user_id is not in attr_accesible atributes

    Read the article

  • What's the use of writing tests matching configuration-like code line by line?

    - by Pascal Van Hecke
    Hi, I have been wondering about the usefulness of writing tests that match code one-by-one. Just an example: in Rails, you can define 7 restful routes in one line in routes.rb using: resources :products BDD/TDD proscribes you test first and then write code. In order to test the full effect of this line, devs come up with macros e.g. for shoulda: http://kconrails.com/2010/01/27/route-testing-with-shoulda-in-ruby-on-rails/ class RoutingTest < ActionController::TestCase # simple should_map_resources :products end I'm not trying to pick on the guy that wrote the macros, this is just an example of a pattern that I see all over Rails. I'm just wondering what the use of it is... in the end you're just duplicating code and the only thing you test is that Rails works. You could as well write a tool that transforms your test macros into actual code... When I ask around, people answer me that: "the tests should document your code, so yes it makes sense to write them, even if it's just one line corresponding to one line" What are your thoughts?

    Read the article

  • Mocha expects method

    - by Masha
    So my situation is: I have a 2 modules that have the same structure like that: module Module1 class Config def fee_rate 2 end end end So, say, Module2 would have class Config with the method fee_rate, just with a different value (those are actually implemented in a rails engine, but it shouldn't matter) and then my model can use either Module1 or Module2 to get the fee rate value like that: def config @config ||= "#{module_name.titleize}::Config".constantize.new @config end def get_value config.get_fee * some_other_value end What I'm trying to test is if get_fee function was called on the correct class: "#{model.module_name.titleize}::Config".constantize.any_instance.expects(:get_fee).at_least_once model.get_value and on the line when I call get_value I get the following error - undefined method `*' for nil:NilClass. I'm completely lost now, so I'd appreciate any help and ideas.

    Read the article

  • How to stub Restul-authentication's current_user method?

    - by Thiago
    Hi there, I'm trying to run the following spec: describe UsersController, "GET friends" do it "should call current_user.friends" do user = mock_model(User) user.should_receive(:friends) UsersController.stub!(:current_user).and_return(user) get :friends end end My controller looks like this def friends @friends = current_user.friends respond_to do |format| format.html end end The problem is that I cannot stub the current_user method, as when I run the test, I get: Spec::Mocks::MockExpectationError in 'UsersController GET friends should call current _user.friends' Mock "User_1001" expected :friends with (any args) once, but received it 0 times[0m ./spec/controllers/users_controller_spec.rb:44: current_user is a method from Restful-authentication, which is included in this controller. How am I supposed to test this controller? Thanks in advance

    Read the article

  • session variable not available in global before(:each, :type => :controller)

    - by Rob
    Hi, I'm refactoring some specs, in controller specs I have a before(:each) which sets up things required in the session my before filter is... config.before(:each, :type => :controller) do ... session[:current_user] = @user session[:instance] = @instance ... end @user and @instance are also set in the before(:each) i've just hidden them for readability here I get the following error when running the controller tests undefined method `session' for nil:NilClass I would expect the global before callbacks to have the same things as the ones in the individual tests but I guess maybe they are loaded before the rails environment has been initialised? Thanks

    Read the article

  • Installed Ruby 1.9.2 but new gems won't create scripts into /usr/bin

    - by karatedog
    I had previously ruby 1.8 on my Ubuntu 10.10, which I removed through Synaptics. Then I have installed ruby 1.9.1 also via Synaptics (which is then saying that itself is version 1.9.2). Then I installed ruby-debug19 and rspec gems with sudo gem install ruby-debug19 rspec However I can't start rdebug or rspec, but I can invoke the debugger from inside my ruby script, so the debugger is working. I inspected the starting scipts rdebug and rspec and then I realized that they are still old scripts back from ruby1.8 time. In other worlds, the current 1.9 install of these gems haven't created the starting scripts anywhere. What is the easiest solution for a lazy soul like me? It looks like removing-reinstalling ruby 1.9.2 won't help, and installing these gems over and over againg won't create the starting scripts.

    Read the article

  • How to test Rails 3 Engines with Cucumber & Rspec?

    - by cowboycoded
    I apologize if this question is slightly subjective... I am trying to figure out the best way to test Rails 3 Engines with Cucumber & Rspec. In order to test the engine a rails 3 app is necessary. Here is what I am currently doing: Add a rails test app to the root of the gem (myengine) by running: rails new /myengine/rails_app Add Cucumber to /myengine/rails_app/features as you would in a normal Rails app Require the Rails Engine Gem (using :path=>"/myengine") in /myengine/rails_app/Gemfile Add spec to the root directory of the gem: /myengine/spec Include the fixtures in /myengine/spec/fixtures and I add the following to my cuc env.rb: env.rb: Fixtures.reset_cache fixtures_folder = File.join(Rails.root, 'spec', 'fixtures') fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') } Fixtures.create_fixtures(fixtures_folder, fixtures) Do you see any problems with setting it up like this? The tests run fine, but I am a bit hesitant to put the features inside the test rails app. I originally tried putting the features in the root of the gem and I created the test rails app inside features/support, but for some reason my engine would not initialize when I ran the tests, even though I could see the app loading everything else when cuc ran. If anyone is working with Rails Engines and is using cuc and rspec for testing, I would be interested to hear your setup.

    Read the article

  • How can I stub out a call to super in a imported Java class in JRuby for testing

    - by Doug Chew
    I am testing Java classes with RSpec and JRuby. How can I stub out a call to super in an imported Java class in my RSpec test? For example: I have 2 Java classes: public class A{ public String foo() { return "bar"; } } public class B extends A public String foo() { // B code return super.foo(); } } I am just trying to test the code in B.foo and not the code in A.foo with JRuby. How can I stub out the call to the super class method in my RSpec test? rspec test: java_import Java::B describe B do it "should not call A.foo" do # some code to stub out A.foo b = B.new b.foo.should_not == "bar" end end I have tried including a module with a new foo method in B's class hoping that it would hit the module method first but B still makes a call to A. The inserting module technique works in Ruby but not with JRuby and imported Java classes. Any other ideas to stub out the superclass method to get my RSpec test to pass?

    Read the article

  • Cucumber can't find installed gems

    - by artemave
    environment/cucumber.rb: ... # gem dependencies config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.0' unless File.directory?(File.join(Rails.root, 'vend config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vend config.gem 'webrat', :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vend config.gem 'spork', :lib => false, :version => '>=0.7.5' unless File.directory?(File.join(Rails.root, 'vend config.gem 'factory_girl', :source => 'http://gemcutter.org' config.gem 'selenium-client', :lib => false config.gem 'Selenium', :lib => false config.gem 'rspec', :lib => 'spec' config.gem 'rspec-rails', :lib => 'spec/rails' config.gem 'test-unit', :lib => false Running cucumber gives missing gems error: artem:~/projects/food4feed (master)$ cucumber ... no such file to load -- test-unit /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/rails/gem_dependency.rb:208:in `load' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `block in load_gems' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `each' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `load_gems' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:169:in `process' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:113:in `run' /home/artem/projects/food4feed/config/environment.rb:9:in `<top (required)>' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require' /home/artem/projects/food4feed/features/support/env.rb:12:in `block in <top (required)>' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/spork-0.8.1/lib/spork.rb:23:in `prefork' /home/artem/projects/food4feed/features/support/env.rb:10:in `<top (required)>' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/rb_support/rb_language.rb:124:in `load_code_file' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:85:in `load_code_file' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:77:in `block in load_code_files' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:76:in `each' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:76:in `load_code_files' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/cli/main.rb:48:in `execute!' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/cli/main.rb:20:in `execute' /home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/bin/cucumber:8:in `<top (required)>' /home/artem/.rvm/gems/ruby-1.9.1-p378/bin/cucumber:19:in `load' /home/artem/.rvm/gems/ruby-1.9.1-p378/bin/cucumber:19:in `<main>' Missing these required gems: selenium-client Selenium rspec-rails test-unit You're running: ruby 1.9.1.378 at /home/artem/.rvm/rubies/ruby-1.9.1-p378/bin/ruby rubygems 1.3.5 at /home/artem/.rvm/gems/ruby-1.9.1-p378, /home/artem/.rvm/gems/ruby-1.9.1-p378%global All gems are obviously there: artem:~/projects/food4feed (master)$ gem list | egrep "elenium|rspec|test-unit" rspec (1.3.0) rspec-rails (1.3.2) Selenium (1.1.14) selenium-client (1.2.18) test-unit (2.0.7) The even more confusing part is that it only complains about certain gems. factory_girl and rspec don't cause problems. Any idea what is going on? My environment: Rails 2.3.5 cucumber (0.6.3) cucumber-rails (0.3.0)

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11  | Next Page >