rspec2

rspec user test gives “undefined local variable or method `confirmed_at' ”

青春壹個敷衍的年華 提交于 2019-12-05 09:45:51
my rspec test is giving me NameError: undefined local variable or method `confirmed_at' for #<User:0xca6ff98> My User spec is: require 'spec_helper' describe User do before(:each) do @user = Factory(:user) end # Factory will make sure that in the future if attributes are added the tests below don't break # Just as long as the Factory is updated for the new attributes as appropriate. context "email is null" do it "record is invalid " do @user.name = nil @user.should_not be_valid end end context "email is unique" do it "record is valid " do @user2 = Factory(:user) @user2 = @user.email @user2

I am having trouble testing my controller's update action using Rspec, what am I doing wrong?

我怕爱的太早我们不能终老 提交于 2019-12-05 08:01:01
问题 I am trying to test the failing branch of the update action on my controller but I am having trouble with the test. This is what I have and it fails on the last describe "PUT 'article/:id'" do . . . describe "with invalid params" do it "should find the article and return the object" do Article.stub(:find).with("1").and_return(@article) end it "should update the article with new attributes" do Article.stub(:update_attributes).and_return(false) end it "should render the edit form" do response

bundle exec rspec VS rspec spec

◇◆丶佛笑我妖孽 提交于 2019-12-05 07:57:05
Ruby 1.9.2 Rails 3.1 Here is the problem bundle exec rspec spec/ does not work, but rspec spec/ runs ok. When I run c:\RailsInstaller\work\apptwit>bundle exec rspec spec/ (this is the directory where my app is located, so the path to spec would not need to be specified) I receive c:/RailsInstaller/work/apptwit/spec/controllers/pages_controller_spec.rb:1:in `require': no such file to load -- spec_he lper (LoadError) from c:/RailsInstaller/work/apptwit/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib

Rspec2 testing a before_validation method

丶灬走出姿态 提交于 2019-12-05 05:27:32
I have the following to remove the spaces on a specific attribute. #before_validation :strip_whitespace protected def strip_whitespace self.title = self.title.strip end And I want to test it. For now, I've tried: it "shouldn't create a new part with title beggining with space" do @part = Part.new(@attr.merge(:title => " Test")) @part.title.should.eql?("Test") end What am I missing? Validations won't run until the object is saved, or you invoke valid? manually. Your before_validation callback isn't being run in your current example because your validations are never checked. In your test I

RSpec response.body is still empty even with config.render_views

喜欢而已 提交于 2019-12-05 02:11:44
In my spec_helper.rb file I have specifically set it to config.render_views but the response.body I get back is still empty. Here is my basic spec describe "#index" do it "should list all rooms" do get 'index' stub(Person).all end it "responds with 200 response code" do response.should be_ok end it "renders the index template" do pp response.body response.should render_template("people/index") end end Is there anything else that could have shorted this behavior? It's fine when I go through the browser. I am on Rspec 2.5.0 Have you tried having render_views in your controller spec file? That

rspec/capybara: how to simulate incoming POST requests? (rack-test won't work)

落花浮王杯 提交于 2019-12-05 01:38:11
问题 I need to receive incoming emails as multipart-formdata via a POST request from Cloudmailin. The POST resembles the following: Parameters: {"to"=>"<email@exmaple.comt>", "from"=>"whomever@example", "subject"=>"my awesome subject line.... Actually, receiving and parsing emails is super easy because the email is just posted as params: params[:to], params[:from], etc. However, how do I simulate this POST request in rails? I built a dummy rails app to test out Cloudmailin, so I have an actual

Rspec: How to suppress warnings and notices when running tests?

陌路散爱 提交于 2019-12-05 01:30:19
I was using Mysql database before and decided to switch to Postgresql and now, when I run my tests using rspec, I getting a lot of warnings and notices. WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has link "Suspender" WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has css "title" with text "Suspensão de anúncio" WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has css "h1" with text "Awesome job!" How can I suppress that? Is

Unwanted symbol to string conversion of hash key

余生长醉 提交于 2019-12-04 17:01:40
问题 When I assign in my controller @my_hash = { :my_key => :my_value } and test that controller by doing get 'index' assigns(:my_hash).should == { :my_key => :my_value } then I get the following error message: expected: {:my_key=>:my_value}, got: {"my_key"=>:my_value} (using ==) Why does this automatic symbol to string conversion happen? Why does it affect the key of the hash? 回答1: It may end up as a HashWithIndifferentAccess if Rails somehow gets ahold of it, and that uses string keys internally

Testing helpers in Rails 3 with Rspec 2 and Devise

时间秒杀一切 提交于 2019-12-04 16:42:08
问题 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

Does an RSpec2 matcher for matching Hashes exist?

99封情书 提交于 2019-12-04 16:26:38
问题 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