search for: be_valid

Displaying 20 results from an estimated 34 matches for "be_valid".

2009 Feb 28
7
be_valid (validates_format_of ..., :on => :create)
...s User < ActiveRecord::Base ... validates_format_of :email, :with => /.../, :on => :create ... Using following code is not right: it "should ..." do @user = users(:example_user) @user.email = ''invalid_email_format'' @user.save @user.should_not be_valid end Even those code is not right: it "should ... " do @user = users(:example_user) @user.email = ''invalid_email_format'' @user.save @user.should be_valid end Thanks.
2012 May 24
0
Ruby on Rails Tutorial Chapter 6 RSpec tests failing
...I''m a RoR newbie who is currently following the Ruby on Rails Tutorial: Learning by Example book (http://ruby.railstutorial.org/ chapters/modeling-users#sec:adding_a_secure_password). The following Chapter 6 RSpec tests are failing: Failures: 1) User [31mFailure/Error:[0m [31mit { should be_valid }[0m [31mexpected valid? to return true, got false[0m [36m # ./spec/models/ user_spec.rb:19:in `block (2 levels) in ''[0m 2) User when email format is valid should be valid [31mFailure/Error: [0m [31m-agIoKRwLymF0sw7Iq073Hg@public.gmane.org be_valid[0m [31mexpected valid? to return true, g...
2007 May 01
2
Problem validating boolean
...nance", :start_date => nil, :balance => 5000, :term => 36, :linked_to_residual_value_of_asset => true) end aspect "validation" do specify "should be valid" do @finance_agreement.should be_valid end specify "should be invalid if linked_to_residual_value_of_asset is not true or false" do @finance_agreement.linked_to_residual_value_of_asset = true @finance_agreement.should be_valid @finance_agreement.linked_to_residual_value_of_asset = f...
2007 Sep 04
16
Failure Messages in RSpec
Having used JUnit and Test::Unit, I''m quite used to having the ability to insert a failure message, which helps when tests fail. For instance, the example RSpec that is generated for a model class specifies that the model class is valid. Assuming this were supposed to be true, and it failed, I''ve now got to duplicate the code in the test in order to find out why it
2007 Nov 29
3
Stylistic preferences
..._attributes(phone_number="12345") { :phone_number => phone_number } end end describe User, "with phone number" do include UserSpecHelper before(:each) do @user = User.new(valid_sms_attributes) end it "should be valid" do @user.should be_valid end it "should reject duplicate phone number" do @user.save @user_2 = User.new(valid_sms_attributes) @user_2.should_not be_valid end it "should be possible to disable the number" do @user.save @user.disable_number @user.should be_disab...
2009 Jan 16
3
rspec model testing - test on user defined validation- How do I test that the create failed.
I''m new to rspec and looking for way to test a validation I added to a model. The test checks to see that if field1 has a value then field2 must be nil and vice versa. ------------------------------- When I did the rspec_scaffold it generated one test which worked before :each do @valid_attributes = { :field1 = "value for field1" :field2 = "value for
2010 Aug 28
1
validates_uniqueness_of missing in rails 3.0 rc2?
...titles.push(Title.new(@valid_title_attributes)) end it "should not have multiple titles with same language attribute" do @book.titles.clear @book.titles.push(Title.new(@valid_title_attributes)) @book.titles.push(Title.new(@valid_title_attributes)) @book.should_not be_valid @book.titles.clear @book.titles.push(Title.new(@valid_title_attributes)) @book.should be_valid end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JY...
2007 Nov 13
2
Trouble stubbing a method
...king was just to stub out Order#payment_authorize. So here is one of my specs: describe Order, "placed via the web" do include OrderSpecHelper before(:each) do @order = generate_valid_web_order @order.should_receive(:payment_authorize) end it do @order.should be_valid end end I''m using a mock for now, just to verify it does get called, once it''s working I''ll change it to a stub. (I want to explicitly test it on another spec) Anyhow, this doesn''t work, but sure enough, the calls out to TrustCommerce are being made. I als...
2008 Mar 03
2
stuck on testing validation
Hello, I must be doing something dumb, but here it goes... why does this work? before(:each) do @work = Work.new end #for testing validates_presence_of :title it "should require a title" do @work.title = nil @work.should_not be_valid end while this doesn''t: def valid_work_attributes { :title => "guernica", :description => "lorem ipsum lorem ipsum", :date => Date.today, :category => Category.new(:name => "belle epoque") } end before(...
2010 Mar 24
2
Mock "Consent_6335" received unexpected message :marked_for_destruction? with (no args)
I have a mock object (Person) that is associated with another object (my_object) through a belongs_to association. When I check whether my_object is valid (my_object.should be_valid), I am getting an error like the following: Mock "Person_6338" received unexpected message :marked_for_destruction? with (no args) Checking the list of methods on the mock, "marked_for_destruction?" is not listed. Is this this something that i should expect to always stub? As...
2008 Jan 23
6
sharing specs in a subclass
Hi I''ve spec''d a class and they pass. Now I''d like to assure that any subclass of this class also passes the same specs. Any suggestions for a clever way to handle this? I''d prefer to keep the existing specs as is (eg instead of moving everything into shared behaviors, or doing something to all the ''describe'' lines) thanks linoj
2010 Aug 11
6
rspec2 not working with shoulda
I am using rails edge. I am using gem "rspec-rails", "= 2.0.0.beta. 19" . I have following code at spec/models/user_spec.rb require ''spec_helper'' describe User do it { should validate_presence_of(:email) } it { should validate_presence_of(:name) } end Here is my gemfile group :development, :test do gem ''factory_girl_rails'',
2007 Nov 09
9
fixture_file_upload and edge rspec?
...mage" do @image.attributes = valid_image_attributes.merge({:uploaded_data => fixture_file_upload(''/textfile.txt'', ''text/plain'')}) @image.should_not be_valid # content_type: is not included in the list @image.should have(1).error_on(:content_type) end which fails with: 2) NoMethodError in ''Image unsaved should be invalid if uploaded file is not an image'' You have a nil object when you didn''t expect it! You might h...
2007 Jul 26
3
Spec for validation plugin
...s_uk_postcode :post_code end In my model spec I want something like this (assume @location has been setup as a new Location instance): it "should be invalid if the post code is incorrectly formatted" do @location.post_code => ''Q1 1QQ'' @location.should_not be_valid @location.should have(1).error_on(:post_code) end But there are many examples of invalid post codes and they are already tested in the plugin''s own test cases. I only really want to test my code, rather than retest the plugin. So my question is how should I write the specificati...
2011 Mar 07
1
@attr.merge?
Hi, What does the @attr.merge in something like: it "should require a password" do User.new(@attr.merge(:password => "", :password_confirmation => "")). should_not be_valid end do? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from...
2007 Dec 11
3
can''t access helper methods for model testing
...member.stub!(:region_code).and_return("234234") return member end end ======= require File.dirname(__FILE__) + ''/../spec_helper'' describe Member do before(:each) do @member = valid_member_mock end it "should be valid" do @member.should be_valid end end ======= NameError in ''Spec::Rails::Example::ModelExampleGroup Member should be valid'' undefined local variable or method `valid_member_mock'' for #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x20e6814> ======= I would assume that rails is includin...
2007 Jul 24
11
Mock or Stub strategy for validates_uniqueness_of
...k" do clip = clips( :some_clip ) book = books( :some_book ) lambda do clipping = Clipping.create( :clip => clip, :book => book ) end.should change( Clipping, :count ).by( 1 ) lambda do clipping = Clipping.create( :clip => clip, :book => ) clipping.should_not be_valid end.should_not change( Clipping, :count ) end Any hints as to how to do this without using fixtures? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070724/d3118a91/attachment-0001.html
2007 Oct 16
12
Example for attr_accessible?
Is anyone out there writing specs to check attr_accessible fields? I had originally written my spec to check for allowing the desired fields, and then none of the other regular db fields. Unfortunately this isn''t satisfactory, because attr_protected could have been used instead, which of course wouldn''t prevent mass assignment to any whatever=(val) method. I''m thinking
2008 Nov 04
9
RSpec and PostgreSQL not playing nicely together
...__FILE__) + ''/../spec_helper'') describe Product, "The Product model" do describe "When a new blank product object gets created" do before(:each) do @product = Product.new end it "should not be valid" do @product.should_not be_valid @product.errors.on(:title).should_not be_nil # plenty other errors to display... end end end -- And here is the error message when I run this spec: -- spec product_spec.rb F 1) ActiveRecord::StatementInvalid in ''Product The Product model When a new blank product object...
2007 May 15
5
Rspec + Oracle
...modifications have not helped me. This is my spec: " require File.dirname(__FILE__) + ''/../spec_helper'' describe Country do before(:each) do @countries = Country.new # @countries = Country.find(:first) end it "should be valid" do @countries.should be_valid end end " Does anybody know how I can use method "new" of model in my Rspec''s files with Oracle? Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group....