Testing for class methods in Ruby
How do you test for the existence of a class method? Test it using #respond_to?
puts "Hello, World!"
And to make sure we are really just talking about class methods and not instance methods:
foo = Foo.new
RubyMine and Rspec2 Bug Fixed!
We use the latest and greatest RubyMine version available at Pivotal, but sometimes technology choices such as Rails 3 and Rspec 2 are still ahead of it. The formatter that analyzes test output breaks on Rspec 2′s output before any tests run. The bug is further discussed http://youtrack.jetbrains.net/issue/RUBY-6485. Luckily this bug will be fixed in the next EAP release.
Excuting .rvmrc commands and cruisecontrol
We’ve had a difficult time getting .rvmrc files to work with cruisecontrol.rb builds. Specifically, ccrb seems to launch the rake task in the project working directory. This means that the .rvmrc file is ignored. A workaround is to have your CI script directly use RVM or to add “
cd .. && cd work” before your project cruise script or rake task.
Ask for Help
- Double-entry/ledger based accounting in Rails (i.e. Quickbooks in Rails for free)
Ideally would be tied in with user/role system where each accounting entry would be tied to a user, but also reconciled against a master account.
Recommendations? Latest and greatest?
One suggestion was to look at the code that Wesabe open sourced code when they closed their doors.
- Error message when opening Rubymine “Invalid Git Root”
This is likely because the project included a submodule that wasn’t configured correctly, fix this in under Rubymine’s version control preferences.
- Test 404 handling (e.g.
rescue_from ActiveRecord::RecordNotFound, :with => :render_record_not_found) with Cucumber by temporarily setting
ActionController::Base.allow_rescue = true. This is usually set to
JSON.pretty_generate hates Rails 3
This should work in most modern browsers. Follow the Mozilla docs, NOT the various blog posts about this.
Ask for Help
- I asked if there’s a date library in Ruby as rich as Java’s JODA
Suggestions included Chronic and RI_CAL though I’m hoping for something that can represent arbitrary periods (ranges?) of time JODA and handles interval calculation and other such date/time arithmetic.
- is(‘:visible’) doesn’t always work as expected in Jasmine
One project reported that using this to as part of a Jasmine spec to ensure that an element becomes visible doesn’t appear to be reliable.
- Annotate and Git History failed for a team using Rubymine 2.0.2 and git 188.8.131.52 in combination with svn.
They solved the problem by downgrading to git 184.108.40.206:
I followed instructions here to create a local set of portfiles:
http://guide.macports.org/#development.local-repositories and grabbed the older portfile from here:
After I could do a port search git-core and have 220.127.116.11 show up, I was able to
sudo port deactivate git-core @1.7.2_0+doc+svn and
sudo port install git-core @18.104.22.168+doc+svn
- One person was experienced compile errors when installing
memprof on Ubuntu, fortunately somebody else had gotten this working before and offered to help him through thee.
- A team noticed that Bundler ran multiple (4) times on CI taking nearly 11mins overall and wanted to know to make Bundler run only once
It was suggested that the problem may be due to the way they’d setup their
preinitializer.rb and they should move the
bundle install into a Rake task.
puts "IS_CI_BOX is set, running
system(‘bundle install’) || raise(“‘bundle install’ command failed. Install bundler with
gem install bundler.”)
It was pointed out that they should make sure their
Gemfile.lock file is checked into version control, which it was. Additionally Bundler 1.0.0 RC1 will allow isolating gems to a local path using
bundle install path --disable-shared-gems
- The Facebook Graph API doesn’t appear to implement OAuth 2.0 properly/completely so it doesn’t work with the OAuth2 gem
- One Pivot noticed that the version of ImageMagick installed on the default EngineYard solo image is out of date and had to upgrade this manually.
RubyMine 2.0.2, refactor => extract partial == FAIL. If you select multiple divs and perform
extract partial, the selected region is removed, but only the first complete div is included in
the new partial.
Rspec/Rubymine focused tests. Rubymine attempts to run focused tests using the
--example 'text' option. Rspec apparently finds the example group, and runs the examples that are
directly a part of that example group, but does not include descendent example groups — *which can
lead you to think examples are passing that were not actually run*. Apparently this is
fixed in rspec 2.
Ask for Help
“Display of time is off by an hour, presumably due to Daylight Saving Time”
The team is displaying time stored as utc in the database, using strftime, and the time is off by an hour.
“Binding Click to Checkbox with Jquery”
A team was trying to check the value of a checkbox during the click event, but getting the opposite
value. They worked through it but was hoping to find a better solution.
“Why is there a new default for include_root_in_json for rails 3?”
“Fakeweb, Capybara w/Selenium Webdriver == end of file?”
Getting “end of file” failure on CI. There were a few suggestions:
- There is a fork of fakeweb that allows it to ignore localhost.
- Consider using Webmock instead of fakeweb.
RubyMine is integrating with Pivotal Tracker! Beta version 2.5 lets you follow stories through the IDE’s task tool and tags your source control comments with the current tasks. It’s nice to see the title of your current story as you work. I’m excited to see what deeper integrations lie ahead. This screenshot shows what it looks like selecting a story through the menu item Tools > Task > Open…
In the the process of pulling assets out of a PDF we’ve noticed Preview crashes opening files larger than 45MB. Adobe Reader opens the same files without problems. Has anyone else had problems with Preview?
I ran into that issue and used the PDF optimizer in Acrobat to pull-out unnecessary markup and compress the images. That seemed to take care of the issue for Preview.
Ask for Help
“We keep getting webrat thread exceptions running our integration specs with the rails integration runner: Thread tried to join itself. The error message varies with different versions of ruby 1.8.6 vs 1.8.7.”
Anyone had this problem or know why?
“How do I skin an iphone mobile site to be the correct width so it’s not 980px wide?”
<meta name="viewport" content="width = device width" />
*”We’re trying to deploy some nginx configuration changes to EngineYard Cloud, what’s the right way to do that?”
We’ve tried building custom chef recipes to solve this problem, but they run after nginx has already restarted, so are a poor solution to this problem. The better solution might be to check in configuration files into the application and symlink them into the nginx configuration directory using a
before_symlink.rb hook in the
*”We’ve got a
has_many association where some of the child records are originally saved in an invalid state. When we later load the parent and ask it if it’s valid, it returns true even with
validates_associated. How can we get the desired validation behavior?”
Turns out that unloaded associations are not validated. Solution: load the association before calling
.valid? on the parent. In general, you should also not create invalid objects, instead using a state variable to put them into a “draft” or “incomplete” state where they are still valid but not complete. Then remove that state and you’ll see the errors required to finish that object.
- When RubyMine 2.0.1 won’t run your focused specs, try attaching rspec 1.2.9 to it rather than 1.3.x. It fixed this issue for one of our teams.
- Rubymine 2.0.2 came out today: can finally run focused contexts?! Also including bundler support! What’s new
- We tried our Unicorn on EngineYard cloud: so far so good. It’s still “experimental” but seems to work.
How do you make a Mac not sleep?
Use the Energy Saver section of the System Preferences.
RubyMine 749 is out. Many of the existing bugs have been fixed, but a few new ones have been found. Notably, running specs with a “#” character in the describe string has problems.
The USPS has a nifty web service for addresses. The zip code lookup (which gives you zip+4) and the address standardization services were found to be useful.
We’re looking for more information about Taste or other similar kinds of suggestion engines. What kind of experiences have people had integrating these tools into Rails applications. Are there other useful engines worth looking at?
Direct uploads to Amazon S3 service can be serviced by EC2 servers; however, there might be more direct ways of doings this with S3.
Newer versions of RubyMine have been reported having problems running the gem version of rspec but a solutions has been found. The problem comes from the way gems are specified in RubyMine. You need to add the rspec gem you are using to the Project Structure >> Ruby SDK and Gems.
Using Desert and exception notifier can cause some slow startup times. If you are seeing this problem try moving exception notifier’s sender_address inside your environment’s post-load block.
You have probably noticed that the changes view is unusable in RubyMine because of all the .svn files showing.
Well if you refresh ( ) the changes view they go away…Hurray!