This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A sample Gemfile | |
source "https://rubygems.org" | |
gem 'rspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect { | |
expect(the_dbl).to have_received(:expected_method).with(:one).once | |
}.to raise_error(Expectations::ExpectationNotMetError, | |
a_string_including("expected: 1 time", | |
"received: 2 times")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :an_exception_caused_by do |cause| | |
match do |exception| | |
cause === exception.cause | |
end | |
end | |
expect { | |
begin | |
"foo".gsub # requires 2 args | |
rescue ArgumentError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sentence | |
def test(sen) | |
first = sen[0] | |
last = sen.split('').last | |
rest = sen[1..-1] | |
word_arr = sen.split | |
word_arr_len = word_arr.length | |
unless first == first.upcase then | |
puts "the first letter is not in uppercase" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to get the name, you can use `instance_variable_get`: | |
tweet = double("Twitter::Tweet") | |
tweet.instance_variable_get(:@name) # => "Twitter::Tweet" | |
# that's clearly violating the public API, though. Another way is to pass it as a stub: | |
tweet = double("Twitter::Tweet", name: "Twitter::Tweet") | |
tweet.name # => "Twitter::Tweet" | |
# If you like that approach, you could create a new `named_double` | |
# helper method: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Delorean.Parallel do | |
def map(list, fun) do | |
list | |
|> Enum.map(fn(item) -> Task.async(fn -> fun.(item) end) end) | |
|> Enum.map(&Task.await/1) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.SnapshotRepositoryTest do | |
use ExUnit.Case, async: true | |
doctest MyApp.SnapshotRepository | |
alias MyApp.SnapshotRepository.SnapshotOptions | |
test "queries S3 with a prefix and returns the matched keys" do | |
options = %SnapshotOptions{ campaign_id: "prod.0.1", backend: "SomeBackend", cycle_type: "week" } | |
prefix = SnapshotOptions.to_key_prefix(options) | |
key_1 = "#{prefix}0/2013-03-19T15:04:50Z/mtoken.json.gz" | |
key_2 = "#{prefix}1/2013-03-19T15:04:50Z/mtoken.json.gz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Delorean.RankingsShardRepository.RunningShard.Supervisor do | |
use Supervisor | |
def start_link(opts) do | |
Supervisor.start_link(__MODULE__, opts, []) | |
end | |
def start_shard(supervisor, shard_opts) do | |
Supervisor.start_child(supervisor, shard_opts) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :heroku do | |
def app_name | |
@app_name ||= Heroku::Command::BaseWithApp.new([]).app | |
end | |
def latest_bundle(timeout = 30) | |
puts "Attempting to get latest bundle..." | |
get_bundle = lambda do | |
bundles = Heroku::Command.run('bundles', {}) | |
bundles.sort { |b1, b2| b1[:created_at] <=> b2[:created_at] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_element(xpath_expression, text, case_insensitive = false) | |
exp = if case_insensitive | |
xpath_expression % ["translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvqxyz')", text.downcase] | |
else | |
xpath_expression % ["text()", text] | |
end | |
unless elem = find(exp) | |
if case_insensitive | |
raise "Failed to find element using locator #{text}" |