I've tried everything to make this work. Here is my problem
if system("command")
-- do something --
else
-- do something else --
end
I obviously wanted to stub the system command. For that you can do something like this in your rspec file:
module Kernel
def system(cmd)
return true
end
end
skip to main |
skip to sidebar
Pages
What i learn in IT
Thursday, 23 January 2014
Thursday, 16 May 2013
rspec rails have_link, have_css
Found this extremely useful. If you want to test helpers or css code use this:
CREDITS TO
CREDITS TO
#Model@user.should have(1).error_on(:username) # Checks whether there is an error in username@user.errors[:username].should include("can't be blank") # check for the error message#Renderingresponse.should render_template(:index)#Redirectingresponse.should redirect_to(movies_path)#Capybara Matchersresponse.body.should have_content("Hello world")response.body.should have_no_content("Hello world")response.body.should have_css("input#movie_title")response.body.should have_css("input#movie_title", :value => "Twelve Angry Men")response.body.should have_css("input", :count => 3) #True if there are 3 input tags in responseresponse.body.should have_css("input", :maximum => 3) # True if there or fewer or equal to 3 input tagsresponse.body.should have_css("input", :minimum => 3) # True if there are minimum of 3 input tagsresponse.body.should have_css("input", :between => 1..3) # True if there 1 to 3 input tagsresponse.body.should have_css("p a", :text => "hello") # True if there is a anchor tag with text helloresponse.body.should have_css("p a", :text => /[hH]ello(.+)/i)# True if there is a anchor tag with text matching regexresponse.body.should have_xpath("//a")response.body.should have_xpath("//a",:href => "google.com")response.body.should have_xpath("//a[@href => 'google.com']")response.body.should have_xpath("//a[contains(.,'some string')]")response.body.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)# can take both xpath and css as input and can take arguments similar to both have_css and have_xpathresponse.body.should have_selector(:xpath, "//p/h1")response.body.should have_selector(:css, "p a#movie_edit_path")# For making capybara to take css as default selectorCapybara.default_selector = :cssresponse.body.should have_selector("input") #checks for the presence of the input tagresponse.body.should have_selector("input", :value =>"Twelve Angry Men") # checks for input tag with valueresponse.body.should have_no_selector("input")# For making capybara to take css as default selectorCapybara.default_selector = :xpathresponse.body.should have_selector("//input") #checks for the presence of the input tagresponse.body.should have_selector("//input", :value =>"Twelve Angry Men") # checks for input tag with value# To access elements inside formresponse.body.should have_field("FirstName") # checks for presence of a input field named FirstName in a formresponse.body.should have_field("FirstName", :value => "Rambo")response.body.should have_field("FirstName", :with => "Rambo")response.body.should have_link("Foo")response.body.should have_link("Foo", :href=>"googl.com")response.body.should have_no_link("Foo", :href=>"google.com")
Friday, 19 April 2013
rails stub chained for rails activerecord::relations
For whenever you have a multiple clauses on a model like:
Product.where(condition).includes(tables)
you can stub this using this
Product.stub_chain(:where, :includes).and_return([what you want])
easy :)
http://apidock.com/rspec/Spec/Mocks/Methods/stub_chain
Product.where(condition).includes(tables)
you can stub this using this
Product.stub_chain(:where, :includes).and_return([what you want])
easy :)
http://apidock.com/rspec/Spec/Mocks/Methods/stub_chain
Labels:
rails,
rspec,
rspecs,
ruby,
ruby on rails,
stub,
stub_chain
Monday, 11 February 2013
just a quick word on indexes
CREDIT TO:
https://tomafro.net/2009/08/using-indexes-in-rails-index-your-associations
https://tomafro.net/2009/08/using-indexes-in-rails-index-your-associations
Many rails developers are great at building applications but have limited experience in database design. As a consequence, projects often have half-baked indexing strategies, and as a result suffer bad performance.To try and improve this I’ve planned a series of posts on indexes, targetted at rails developers. In this first post I’ll introduce indexes and how to index your associations, then I’ll write about choosing additional indexes to improve query performance, and finally how to avoid redundant and duplicate indexes.A brief overview of database indexes
Wikipedia states that ‘a database index is a data structure that improves the speed of operations on a database table’. Unfortunately, this improvement comes at a cost.For every index on a table, there is a penalty both when inserting and updating rows. Indexes also take up space on disk and in memory, which can affect the efficiency of queries. Finally, having too many indexes can cause databases to choose between them poorly, actually harming performance rather than improving it.So while indexing is important, we shouldn’t just throw indexes at our slow queries: we need to choose carefully how to index our data.Indexing simple associations
By far the most common performance problem I’ve encountered in rails projects is a lack of indexes on foreign keys. There’s no real excuse for this – not indexing foreign keys can cripple your app.
Monday, 21 January 2013
ruby/rails csv skip first row
I've been looking for a solution to this problem for ages now.
http://stackoverflow.com/a/7727809
CREDIT TO:This question kept popping up when i was searching for how to skip the first line with the CSV / FasterCSV libraries, so here's the solution that if you end up here.
the solution is...CSV.foreach("path/to/file.csv",{:headers=>:first_row}) do |row|
HTH.
http://stackoverflow.com/a/7727809
Wednesday, 21 November 2012
android sdk on mac osx
so i started with this tutorial :
http://buildcontext.com/blog/2009/installing-android-sdk-browser-testing-mac-os-x
what you really want is here:
http://stackoverflow.com/a/7962765
http://buildcontext.com/blog/2009/installing-android-sdk-browser-testing-mac-os-x
what you really want is here:
http://stackoverflow.com/a/7962765
If you are getting the error XML verification failed for https://dl-ssl.google.com/android/repository/repository.xml. Error: cvc-elt.1: Cannot find the declaration of element 'sdk:sdk- repository'. Failed to fetch URL
in mac os, then download android sdk (Mac OS X (intel) android-sdk_r15-macosx.zip) from http://developer.android.com/sdk/index.html. Unzip this package and copy this unzip package on your mac root directory (Macintosh HD) and rename this unzip package as android-sdk. Now open android-sdk->tools->android. The sdk update will start automatically. You dont need to install java 6. It is automatically installed in your mac os.
Monday, 19 November 2012
ruby regex expressions
While working with regex expression i found two values resources:
and this cheat sheet for regular expressions
Labels
- add_column (2)
- alias (1)
- Android (2)
- api (2)
- arguments (1)
- autocomplete (1)
- bang (1)
- border (1)
- browser (1)
- check (1)
- css (1)
- csv (1)
- darnket (1)
- data (2)
- database (1)
- db:migrate (1)
- debugger (1)
- default (1)
- default user (1)
- development (2)
- down (1)
- effects (1)
- Emacs (4)
- Emacs24 (1)
- eventmachine (2)
- expectations (1)
- factory girl (2)
- file (1)
- first (1)
- focus (1)
- function (1)
- gem (1)
- git (2)
- highlights (1)
- html (1)
- ie7 (1)
- index (1)
- internet (1)
- Iphone (1)
- javascript (3)
- jquery (3)
- jquery-ui (1)
- JQUERY. toggleClass (1)
- key biding (1)
- mac (2)
- mac osx (3)
- method (1)
- migrations (2)
- mock (2)
- mocks (2)
- mongodb (1)
- MySQL (3)
- namespace (1)
- operators (1)
- optimizing (1)
- password (1)
- popup (1)
- postgresql (2)
- RAIL_ENV (1)
- rails (16)
- regex (1)
- regular expressions (1)
- remove_column (1)
- repair (1)
- repository (1)
- resize (1)
- rspec (7)
- rspecs (6)
- ruby (16)
- ruby on rails (12)
- sdk (1)
- select (2)
- server (1)
- shortcut (1)
- specs (3)
- stash (1)
- stub (4)
- stub_chain (1)
- terminal (2)
- test (1)
- traits (1)
- trusted source (1)
- tutorial (1)
- Ubuntu (6)
- validation (1)
- value (1)
- viewport (1)
- windows (1)
- windows7 (1)
Blog Archive
Powered by Blogger.