| #!/usr/bin/env ruby | |
| # Automatically convert most of the syntax differences between Mocha and RSpec | |
| # Mocks. | |
| # | |
| # Does not handle: | |
| # - Multiline statements like `Foo\n.expects` | |
| # - `with` being given a block | |
| # - Probably other things | |
| # |
This post is adapted from my answer to this Stack Overflow question. If you want to start from the beginning of the universe and build out, go read that one. If you prefer to start with something you can touch and work backwards, here we go.
Ruby likes ducks. Which is to say that when we're coding, and we have an
object, we don't particularly care what kind of object it is, so long as it
responds to the messages we send it. It might be a Duck or a Child or a
| $ rails c | |
| Loading development environment (Rails 4.1.2) | |
| [1] pry(main)> Specialist.find(15) | |
| Specialist Load (0.9ms) SELECT "specialists".* FROM "specialists" WHERE "specialists"."id" = $1 LIMIT 1 [["id", 15]] | |
| => #<Specialist id: 15, ...> | |
| [2] pry(main)> ActiveRecord::Base.logger.silence(Logger::FATAL) { Specialist.find(16) } | |
| => #<Specialist id: 16, ...> |
| # All colors on all applications | |
| $ for app in `heroku apps | tail -n +2`; do heroku config --app $app | cut -d':' -f1 | grep HEROKU_POSTGRESQL | cut -d_ -f3; done | sort | uniq -c | sort -rn | |
| 4 WHITE | |
| 3 CHARCOAL | |
| 2 YELLOW | |
| 2 ORANGE | |
| 2 ONYX | |
| 2 CRIMSON | |
| 2 COBALT | |
| 2 BRONZE |
| # $auth from auth.sh | |
| # $spreadsheet_id from get_spreadsheets.sh | |
| # $worksheet_id from get_worksheets.sh | |
| curl \ | |
| --header "Authorization: GoogleLogin auth=$auth" \ | |
| --header 'Content-Type: application/atom+xml' \ | |
| -d @data.xml \ | |
| -X POST \ | |
| "https://spreadsheets.google.com/feeds/list/$spreadsheet_id/$worksheet_id/private/full" | |
| # Example data in data.xml |
Disclaimer: None of this code was actually run!
A way to handle something that happens asynchronously. Instead of getting your result back, you get a promise back that you can handle in a success way and a failure way. At some point in the future, the promise resolves to one of those cases, passing your success/failure functions the applicable data.
I hereby claim:
- I am kristjan on github.
- I am kristjan (https://keybase.io/kristjan) on keybase.
- I have a public key whose fingerprint is 90B8 10A8 031E E111 893B 49B4 9455 B368 7480 A7AA
To claim this, I am signing this object:
| module RequireImplementation | |
| def require_implementation(method_name) | |
| define_method method_name do | |
| raise NotImplementedError, "#{self.class.name} must implement #{method_name}" | |
| end | |
| end | |
| end | |
| class TestClass |





