Fix Rcov After Upgrade Rspec to 2.8
Rcov doesn’t work after I upgrade rspec to 2.8,
here is a quick fix
add following code into your spec_helper
Rcov doesn’t work after I upgrade rspec to 2.8,
here is a quick fix
add following code into your spec_helper
You’ll find rack parse uploaded file in different format to Rails
Here is the format in rack app.
You can simply covert it to right format.
How to test
If you are using Rails as your backend, Reskit will have trouble to parse ActiveRecord timestamp.
Default ActiveRecord timestamp JSON out is 2008-12-29T00:27:42-08:00
You can not convert it to NSDate directly use NSDateFomatter
you must convert it to 2008-12-29T00:27:42-0800
But you have not chance to convert when you use Restkit Mapping.
Here is my solution
1. Monkey patch Time and DateTime class
2. Add default date fomatter to RKObjectMapping
By default, devise will redirect to login path if session timeout.
So user will redirect to login path when visit page do not need login after session timeout.
To solve this problem you can follow these steps:
config/initializers/devise.rbDeviseFailureAppUsage:
This is a guest blog posted on rubylearning.com
Ruby, as a dynamic language, is always used for quick processing command-line tool for its simplicity and productivity.
This article talks about three ways to write a command-line tool.
Before we start, there are a few things you need to know:
#!/usr/bin/env ruby into the first line of your command-line file which will tell shell execute your file use Rubychmod u+x FILE_PATHOther people will not sure how to execute your command-line tool.
I’ll use three definitions:
For example there is a command: ‘server start -e development’
We start from a simple example: write a command-line tool to start and stop the server.
ARGV, all arguments will stored as a array in this variable.
What if you need to pass some option?
This code is simple but it has some disadvantages:
OptionParser is build-in ruby lib help you parse arguments.
we can refactor our code like this:
Try to execute this file without argument, you’ll find it prints very nice help text.
opt_parser.parse! is the method extract options from ARGV, extracted value will be deleted from ARGV.
OptionParser is better than that.
You can define options value type, then OptionParser will convert value to the type you defined like this:
You can mark whether value of the option is mandatory.
For more details your can see this article and ruby rdoc
Benefit of OptionParser is: we don’t need to use array index to retrieve options and we write help text along with option definition.
Disadvantage of OptionParser is: since different commands need using the same option parser, you cannot define different option parsers for different commands. To solve this problem, you can resort to Thor.
As you know Thor is a replacement of Rake. Let’s see how we use Thor to refactor our command-line tool.
desc defines command name and long description method_option define option parser for this commandThorExample.start is method to start parse argumentExecute it without argument, the output is:
Execute it with argument help start, you’ll get help text for command start:
As you can see, it’s very clean and easy to write.
For more detailed usage, you can visit Thor github page and its rdoc
Of course there are more ways to write command-line tool. Choose what best fit your requirement rather than the most powerful or latest one.
All the sample code is on github https://github.com/allenwei/ruby_command_line_sample
You can see, there are lot’s of useful info in Constant RbConfig::CONFIG
First, make sure your Capybara version is >= 0.4.0
Then, download firebug plugin and save it to features/support/firebug-1.6.0-fx.xpi
And add following line into features/support/env.rb
You will found that firefox will create a new firebug page tab. I have no idea how to close it, but seems it doesn’t affect our test result.
Today we met a strong problem. One of our constant is changed out of my expectation.
In my mind, constant is the variable we can not change, but actually we are half right.
See code bellow:
You may say, I won’t change constant like that. But what if you assign a new variable to a constant, like:
I’m sure not everyone knows we can change constant “internally”.
So for sure, we can freeze our constant
As we eval some code on runtime, but do you know eval is slow?
A best practice is move eval from uuntime to parse time
Here is the benchmark:
Here is the code
Ads Plugin created by Jake Ruston's Wordpress Plugins - Powered by and football database.