Command Line
pry -r ./config/app_init_file.rb- load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb- load your rails into a pry session
Debugger
| # RSpec's subject method, both implicitly and explicitly set, is useful for | |
| # declaratively setting up the context of the object under test. If you provide a | |
| # class for your describe block, subject will implicitly be set to a new instance | |
| # of this class (with no arguments passed to the constructor). If you want | |
| # something more complex done, such as setting arguments, you can use the | |
| # explicit subject setter, which takes a block. | |
| describe Person do | |
| context "born 19 years ago" do | |
| subject { Person.new(:birthdate => 19.years.ago } | |
| it { should be_eligible_to_vote } |
| # ... | |
| gem 'carrierwave' | |
| gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL |
| # Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })} | |
| RSpec::Matchers.define :accept_nested_attributes_for do |association| | |
| match do |model| | |
| @model = model | |
| @nested_att_present = model.respond_to?("#{association}_attributes=".to_sym) | |
| if @nested_att_present && @reject | |
| model.send("#{association}_attributes=".to_sym,[@reject]) | |
| @reject_success = model.send("#{association}").empty? | |
| end | |
| model.send("#{association}").clear |
| require 'benchmark' | |
| REP = 100_000 | |
| dat = [1, 2, 3, 2, 4, 5, 4, 4] | |
| Benchmark.bmbm 25 do |x| | |
| x.report "Jan low level" do | |
| REP.times do | |
| dups = {} |
| module ApplicationHelper | |
| # thanks to http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/ | |
| # you may need to change the owner of the tmp/cache/* directories to the web servers user | |
| # e.g. for Debian systems: `chown -R www-data:www-data tmp/cache/*` | |
| def render_asset(asset) | |
| Conferator::Application.assets.find_asset(asset).body.html_safe | |
| end | |
| end |
| describe('Core_loadData', function () { | |
| var id = 'testContainer'; | |
| beforeEach(function () { | |
| this.$container = $('<div id="' + id + '"></div>').appendTo('body'); | |
| }); | |
| afterEach(function () { | |
| if (this.$container) { | |
| this.$container.remove(); |
| Capybara.register_driver :chrome do |app| | |
| Capybara::Selenium::Driver.new(app, | |
| browser: :chrome, | |
| desired_capabilities: { | |
| "chromeOptions" => { | |
| "args" => %w{ window-size=1024,768 } | |
| } | |
| } | |
| ) | |
| end |
| # Drop this into /spec/support/matchers | |
| # Usage: result.should be_url | |
| # Passes if result is a valid url, returns error "expected result to be url" if not. | |
| # Matcher to see if a string is a URL or not. | |
| RSpec::Matchers.define :be_url do |expected| | |
| # The match method, returns true if valie, false if not. | |
| match do |actual| | |
| # Use the URI library to parse the string, returning false if this fails. | |
| URI.parse(actual) rescue false |
Command Line
pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb - load your rails into a pry sessionDebugger
| require 'rdoc' | |
| converter = RDoc::Markup::ToMarkdown.new | |
| rdoc = File.read(ARGV[0] || 'README.rdoc') | |
| puts converter.convert(rdoc) | |
| # ruby rdoc2md.rb > README.md | |
| # ruby rdoc2md.rb ABC.rdoc > abc.md |