source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/12-html-table-v1.rb | Ruby | mit | 206 | main | 361 | require 'cgi/escape'
class HTMLTable
def initialize(rows)
@rows = rows
end
def to_s
html = String.new
html << "<table><tbody>"
@rows.each do |row|
html << "<tr>"
row.each do |cell|
html << "<td>" << CGI.escapeHTML(cell.to_s) << "</td>"
end
html << "</tr>"
end
... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/10-dependency-inversion-current-day-v3.rb | Ruby | mit | 206 | main | 344 | class CurrentDay
def initialize(date: Date.today,
schedule: MonthlySchedule.new(date.year,
date.month))
@date = date
@schedule = schedule
end
def work_hours
@schedule.work_hours_for(@date)
end
def workday?
!@schedule.holidays.in... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/06-open-closed.rb | Ruby | mit | 206 | main | 1,409 | class OpenClosed
def self.meths(m)
m.instance_methods + m.private_instance_methods
end
def self.include(*mods)
mods.each do |mod|
unless (meths(mod) & meths(self)).empty?
raise "class closed for modification"
end
end
super
end
singleton_class.alias_method :prepend, :inclu... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/04-single-responsibility-builder-modifier.rb | Ruby | mit | 206 | main | 269 | builder = TextBuilder.new
builder.append("test")
builder.append("ing...1...2")
modifier = TextModifier.new
name = modifier.gsub(ARGV[1].to_s, 'cool', 'amazing')
name = modifier.capitalize(name)
builder.append(". Found: ")
builder.append(name)
puts builder.as_string |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/chapter-02.rb | Ruby | mit | 206 | main | 6,147 | ### 2
### Designing Useful Custom Classes
## Learning when to create a custom class
stack = []
# add to top of stack
stack.push(1)
# get top value from stack
stack.pop
# --
# add to bottom to stack!
stack.unshift(2)
# --
class Stack
def initialize
@stack = []
end
def push(value)
@stack.push(value... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/09-dependency-inversion-current-day-v2.rb | Ruby | mit | 206 | main | 260 | class CurrentDay
def initialize(date: Date.today)
@date = date
@schedule = MonthlySchedule.new(date.year, date.month)
end
def work_hours
@schedule.work_hours_for(@date)
end
def workday?
!@schedule.holidays.include?(@date)
end
end |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/02-symbol-stack.rb | Ruby | mit | 206 | main | 367 | class SymbolStack
def initialize
@stack = []
end
def push(sym)
raise TypeError, "can only push symbols onto stack" unless sym.is_a?(Symbol)
@stack.push([sym, clock_time])
end
def pop
sym, pushed_at = @stack.pop
[sym, clock_time - pushed_at]
end
private def clock_time
Process.clo... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/05-single-responsibility-reports.rb | Ruby | mit | 206 | main | 322 | report = Report.new(data)
puts report.format
report_content = ReportContent.new(data)
report_formatter = ReportFormatter.new
puts report_formatter.format(report_content)
report_content = ReportContent.new(data)
report_formatter = ReportFormatter.
for_type(report_type).new
puts report_formatter.format(report_content... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter02/14-html-table-v3.rb | Ruby | mit | 206 | main | 469 | class HTMLTable
def wrap(html, type)
html << "<" << type << ">"
yield
html << "</" << type << ">"
end
def to_s
html = String.new
wrap(html, 'table') do
wrap(html, 'tbody') do
@rows.each do |row|
wrap(html, 'tr') do
row.each do |cell|
wrap(html... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter06/01-csv.rb | Ruby | mit | 206 | main | 707 | CSV.new(data,
nil_value: "",
strip: true,
skip_lines: /foo/)
# or
CSV.new(data,
col_sep: "\t",
row_sep: "\0",
quote_char: "|")
options = CSV::Options.new
options.nil_value = ""
options.strip = true
options.skip_lines = true
CSV.new(data, options)
# or
options = CSV::Opti... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter06/00-xyz-point.rb | Ruby | mit | 206 | main | 515 | class XYZPoint
def all_combinations(array)
xs.each do |x|
ys.each do |y|
zs.each do |z|
array.each do |val|
yield x, y, z, val
end
end
end
end
end
end
class XYZPoint
private def each_xy
xs.each do |x|
ys.each do |y|
yield x, y
... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter06/chapter-06.rb | Ruby | mit | 206 | main | 2,461 | ### 6
### Formatting Code for Easy Reading
## Recognizing different perspectives to code formatting
bar if foo
# --
if foo
bar
end
# --
foo and bar
# --
return unless condition
# --
unless condition
return
end
# --
if !condition
return
end
# --
condition or return
## Learning how syntactic consiste... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter15/chapter-15.rb | Ruby | mit | 206 | main | 526 | ### 15
### The Database Is Key
## Treating the database as not just dumb storage
# SELECT first_name || ' ' || last_name FROM names;
# --
# SELECT first_name, last_name FROM names
# --
"#{row[:first_name]} #{row[:last_name]}"
## Choosing the model layer
tracks = 10
Album.where("num_tracks > ?", tracks).to_a
# ... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/06-extract-class-v2.rb | Ruby | mit | 206 | main | 1,089 | class Address
def initialize(street, city, state, zip)
@street = street
@city = city
@state = state
@zip = zip
end
def format_label
<<~END
#{@street}
#{@city}, #{@state} #{@zip}
END
end
end
class Client
def initialize(first_name, last_name, street, city,
stat... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/00-extract-method-v1.rb | Ruby | mit | 206 | main | 438 | class Database
def insert(*args)
conn = checkout_connection
conn.execute(insert_sql(*args))
ensure
checkin_connection(conn) if conn
end
def update(*args)
conn = checkout_connection
conn.execute(update_sql(*args))
ensure
checkin_connection(conn) if conn
end
def delete(*args)
c... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/10-constant-deprecation.rb | Ruby | mit | 206 | main | 221 | class Foo
BAR = 1
deprecate_constant :BAR
end
class Foo
BAR = 1
BAR_ = BAR
private_constant :BAR_
deprecate_constant :BAR
end
class Object
Foo_ = Foo
private_constant :Foo_
deprecate_constant :Foo
end |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/05-extract-class-v1.rb | Ruby | mit | 206 | main | 950 | class Client
def initialize(first_name, last_name, street, city,
state, zip, phone)
@first_name = first_name
@last_name = last_name
@street = street
@city = city
@state = state
@zip = zip
@phone = phone
end
def update_phone(phone)
@phone = phone
end
def updat... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/08-method-deprecation.rb | Ruby | mit | 206 | main | 298 | def method_to_be_removed
warn("#{__callee__} is deprecated",
uplevel: 1, category: :deprecated)
# ...
end
def method_to_be_removed
warn("#{__callee__} is deprecated",
uplevel: 1, category: :deprecated)
_method_to_be_removed
end
private def _method_to_be_removed
# ...
end |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/01-extract-method-v2.rb | Ruby | mit | 206 | main | 426 | class Database
private def checkout
conn = checkout_connection
yield conn
ensure
checkin_connection(conn) if conn
end
def insert(*args)
checkout do |conn|
conn.execute(insert_sql(*args))
end
end
def update(*args)
checkout do |conn|
conn.execute(update_sql(*args))
end... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/03-extract-method-v4.rb | Ruby | mit | 206 | main | 403 | class Database
private def checkout
conn = checkout_connection
yield conn
ensure
checkin_connection(conn) if conn
end
private def execute(sql)
checkout do |conn|
conn.execute(sql)
end
end
def insert(*args)
execute(insert_sql(*args))
end
def update(*args)
execute(upda... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/07-extract-class-v3.rb | Ruby | mit | 206 | main | 891 | class Address
def initialize(street, city, state, zip)
@street = street
@city = city
@state = state
@zip = zip
end
def format_label(addressee)
<<~END
#{addressee}
#{@street}
#{@city}, #{@state} #{@zip}
END
end
end
class Client
def initialize(first_name, last_name, address... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/02-extract-method-v3.rb | Ruby | mit | 206 | main | 400 | class Database
private def checkout
conn = checkout_connection
yield conn
ensure
checkin_connection(conn) if conn
end
private def execute
checkout do |conn|
conn.execute(yield)
end
end
def insert(*args)
execute{insert_sql(*args)}
end
def update(*args)
execute{update_... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/09-argument-change.rb | Ruby | mit | 206 | main | 435 | def arg_to_be_removed(arg)
# ...
end
def arg_to_be_removed(arg=(arg_not_given=true; nil))
unless arg_not_given
warn("Passing deprecated argument to #{__callee__}",
uplevel: 1, category: :deprecated)
end
# ...
end
def arg_to_be_added(arg, arg2=(arg2_not_given=true; nil))
if arg2_not_given
w... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/04-extract-method-v5.rb | Ruby | mit | 206 | main | 326 | class Database
private def execute(sql)
conn = checkout_connection
conn.execute(sql)
ensure
checkin_connection(conn) if conn
end
def insert(*args)
execute(insert_sql(*args))
end
def update(*args)
execute(update_sql(*args))
end
def delete(*args)
execute(delete_sql(*args))
end... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter12/chapter-12.rb | Ruby | mit | 206 | main | 5,663 | ### 12
### Handling Change
## Implementing the most common Ruby refactoring techniques
class Database
def insert(*args)
conn = checkout_connection
conn.execute(insert_sql(*args))
ensure
checkin_connection(conn) if conn
end
# --
def update(*args)
conn = checkout_connection
conn.execute(up... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/07-struct-new.rb | Ruby | mit | 206 | main | 462 | def Struct.new(name, *fields)
unless name.is_a?(String)
fields.unshift(name)
name = nil
end
subclass = Class.new(self)
if name
const_set(name, subclass)
end
# Internal magic to setup fields/storage for subclass
def subclass.new(*values)
obj = allocate
obj.initialize(*values)
ob... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/03-album-database-array-hash.rb | Ruby | mit | 206 | main | 388 | album_infos = 100.times.flat_map do |i|
10.times.map do |j|
["Album #{i}", j, "Artist #{j}"]
end
end
albums = {}
album_infos.each do |album, track, artist|
album_array = albums[album] ||= [[]]
album_array[0] << artist
(album_array[track] ||= []) << artist
end
albums.each_value do |array|
array[0].uniq!... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/05-lookup-by-artist-hash.rb | Ruby | mit | 206 | main | 291 | album_infos = 100.times.flat_map do |i|
10.times.map do |j|
["Album #{i}", j, "Artist #{j}"]
end
end
album_artists = {}
album_infos.each do |_, _, artist|
album_artists[artist] ||= true
end
lookup = ->(artists) do
artists.select do |artist|
album_artists[artist]
end
end |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/01-album-database-nested-hash.rb | Ruby | mit | 206 | main | 382 | album_infos = 100.times.flat_map do |i|
10.times.map do |j|
["Album #{i}", j, "Artist #{j}"]
end
end
albums = {}
album_infos.each do |album, track, artist|
((albums[album] ||= {})[track] ||= []) << artist
end
lookup = ->(album, track=nil) do
if track
albums.dig(album, track)
else
a = albums[albu... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/chapter-01.rb | Ruby | mit | 206 | main | 4,787 | ### 1
### Getting the Most out of Core Classes
## Learning when to use core classes
things = ["foo", "bar", "baz"]
things.each do |thing|
puts thing
end
# --
things = ThingList.new("foo", "bar", "baz")
things.each do |thing|
puts thing
end
## Best uses for true, false, and nil objects
1.kind_of?(Integer)
# =>... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/00-album-database-2-hash.rb | Ruby | mit | 206 | main | 461 | album_infos = 100.times.flat_map do |i|
10.times.map do |j|
["Album #{i}", j, "Artist #{j}"]
end
end
album_artists = {}
album_track_artists = {}
album_infos.each do |album, track, artist|
(album_artists[album] ||= []) << artist
(album_track_artists[[album, track]] ||= []) << artist
end
album_artists.each_v... |
github | PacktPublishing/Polished-Ruby-Programming | https://github.com/PacktPublishing/Polished-Ruby-Programming | Chapter01/06-lookup-by-artist-set.rb | Ruby | mit | 206 | main | 219 | album_infos = 100.times.flat_map do |i|
10.times.map do |j|
["Album #{i}", j, "Artist #{j}"]
end
end
album_artists = Set.new(album_infos.flat_map(&:last))
lookup = ->(artists) do
album_artists & artists
end |
github | codeforamerica/civic-tech-patterns | https://github.com/codeforamerica/civic-tech-patterns | html_generator/Rakefile | Ruby | bsd-3-clause | 206 | master | 2,171 | ##
# Copied from middleman-gh-pages
# Modified to link to non-standard project home
# https://github.com/neo/middleman-gh-pages
##
require 'fileutils'
def remote_name
ENV.fetch("REMOTE_NAME", "origin")
end
PROJECT_ROOT = File.join(`git rev-parse --show-toplevel`.strip, 'html_generator')
BUILD_DIR = File.join(PR... |
github | codeforamerica/civic-tech-patterns | https://github.com/codeforamerica/civic-tech-patterns | html_generator/config.rb | Ruby | bsd-3-clause | 206 | master | 2,322 | require 'pathname'
require 'ostruct'
require 'nokogiri'
PROJECT_ROOT = Pathname.new("#{Middleman::Application.root}/..")
###
# Compass
###
# Change Compass configuration
# compass_config do |config|
# config.output_style = :compact
# end
###
# Page options, layouts, aliases and proxies
###
# Per-page layout chang... |
github | codeforamerica/civic-tech-patterns | https://github.com/codeforamerica/civic-tech-patterns | html_generator/Gemfile | Ruby | bsd-3-clause | 206 | master | 235 | source 'http://rubygems.org'
gem 'middleman', '~>3.2.0'
gem 'haml'
gem 'redcarpet'
gem 'nokogiri'
gem 'compass'
gem 'bootstrap-sass', '~> 3.0.2.0'
gem 'middleman-livereload', '~> 3.1.0'
gem 'middleman-pry'
gem 'middleman-gh-pages' |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | Rakefile | Ruby | mit | 206 | main | 289 | # frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require_relative "tasks/spec_tasks"
RSpec::Core::RakeTask.new(:spec)
task default: :spec
begin
require 'gemika/tasks'
rescue LoadError
puts 'Run `gem install gemika` for additional tasks'
end |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | capybara-lockstep.gemspec | Ruby | mit | 206 | main | 1,616 | require_relative "lib/capybara-lockstep/version"
Gem::Specification.new do |spec|
spec.name = "capybara-lockstep"
spec.version = Capybara::Lockstep::VERSION
spec.authors = ["Henning Koch"]
spec.email = ["henning.koch@makandra.de"]
spec.summary = "Synchronize Capybara comma... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | Gemfile | Ruby | mit | 206 | main | 958 | # frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in capybara-lockstep.gemspec
gemspec
gem 'activesupport', '~> 8.0'
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rspec-wait", '~> 0.0.10' # we test with Ruby 2.x, and 1.0.0 requires 3.x
gem 'sinatra'
gem 'thin' # ruby 3... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/spec_helper.rb | Ruby | mit | 206 | main | 1,960 | require 'byebug'
# Require all drivers manually before they get required
# by capybara-lockstep to show better error feedback.
require 'selenium-webdriver'
require 'capybara/cuprite'
require "capybara-lockstep"
require 'capybara'
require 'capybara/rspec'
require "rspec/wait"
require 'active_support/dependencies/autol... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/lib/capybara-lockstep/lockstep_spec.rb | Ruby | mit | 206 | main | 1,203 | module Capybara
describe Lockstep do
describe '#with_mode' do
it 'uses a different mode for the duration of the block' do
expect(Capybara::Lockstep.mode).to eq(:auto)
block_spy = double('block spy')
expect(block_spy).to receive(:observe).with(:manual)
Capybara::Lockstep.wi... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/lib/capybara-lockstep/helper_spec.rb | Ruby | mit | 206 | main | 952 | module Capybara
module Lockstep
describe Helper do
subject do
object = Object.new
object.extend(Helper)
object
end
describe '#capybara_lockstep_js' do
it 'returns the CapybaraLockstep helper' do
expect(subject.capybara_lockstep_js).to include('window.... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/lib/capybara-lockstep/capybara_ext_spec.rb | Ruby | mit | 206 | main | 2,972 | describe Capybara::Lockstep::SynchronizeMacros do
after do
# called after each example, messes with our expectations
allow(Capybara).to receive(:reset_sessions!)
end
let(:example_class) do
Class.new do
def do_something
end
def call_do_something
do_something
end
en... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/wall.rb | Ruby | mit | 206 | main | 547 | class Wall
def initialize
@queue = Queue.new
@mutex = Mutex.new
end
def block
self.class.blocking_walls.push(self)
@queue.pop # this will block until #release pushses a value
end
def release
self.class.blocking_walls.delete(self)
@queue.push(:value)
end
delegate :num_waiting, t... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/app.rb | Ruby | mit | 206 | main | 986 | require 'sinatra'
require 'active_support/core_ext/class/attribute'
class App < Sinatra::Base
include Capybara::Lockstep::Helper
class_attribute :start_html, :start_script, :next_action
delegate :start_html, :start_script, :next_action, :reset, to: :class
get '/' do
render_body(<<~HTML)
Root page
... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/observable_command.rb | Ruby | mit | 206 | main | 598 | class ObservableCommand
def initialize(&block)
@state = :initialized
@block = block
@error = nil
end
attr_reader :state, :error
# Don't name it #call or expect() and wait() will automatically call it
def execute
@state = :running
Thread.new do
@block.call
@state = :finished
... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/matchers/have_ready_state.rb | Ruby | mit | 206 | main | 403 | RSpec::Matchers.define :have_ready_state do |expected_ready_state|
match(notify_expectation_failures: true) do |selector_or_element|
if selector_or_element.is_a?(String)
element = page.find(selector_or_element)
else
element = selector_or_element
end
ready_state = element.evaluate_script(... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/matchers/run_into_wall.rb | Ruby | mit | 206 | main | 409 | RSpec::Matchers.define :run_into_wall do |wall|
include RSpec::Wait
match(notify_expectation_failures: true) do |command|
expect(command).to be_initialized
expect(wall).to_not be_blocking
command.execute
expect(command).to be_running
wait(0.5.seconds).for { wall }.to be_blocking
sleep(0.... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/matchers/be_broken_image.rb | Ruby | mit | 206 | main | 349 | RSpec::Matchers.define :be_broken_image do
match do |selector_or_element|
if selector_or_element.is_a?(String)
element = page.find(selector_or_element)
else
element = selector_or_element
end
is_broken = element.evaluate_script('this.complete && this.naturalWidth === 0')
expect(is_br... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/matchers/be_media_element_with_metadata.rb | Ruby | mit | 206 | main | 377 | RSpec::Matchers.define :be_media_element_with_metadata do
match(notify_expectation_failures: true) do |selector_or_element|
if selector_or_element.is_a?(String)
element = page.find(selector_or_element)
else
element = selector_or_element
end
ready_state = element.evaluate_script('this.rea... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/support/matchers/be_loaded_image.rb | Ruby | mit | 206 | main | 431 | RSpec::Matchers.define :be_loaded_image do
match do |selector_or_element|
if selector_or_element.is_a?(String)
element = page.find(selector_or_element)
else
element = selector_or_element
end
# Cannot just use the #complete property, as this is also true for broken image
is_loaded = e... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/features/synchronization_spec.rb | Ruby | mit | 206 | main | 13,366 | describe 'synchronization' do
describe 'on click' do
it 'waits until an AJAX request has finished' do
App.start_html = <<~HTML
<a href="#" onclick="fetch('/next')">label</a>
HTML
wall = Wall.new
App.next_action = -> { wall.block }
visit '/start'
command = Observable... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | spec/features/rack_test_spec.rb | Ruby | mit | 206 | main | 1,242 | describe 'rack test', driver: :rack_test do
it 'does not blow up' do
App.start_html = <<~HTML
<h1>Hallo App</h1>
<a href="/next" onclick="fetch('/next')">To Next</a>
HTML
App.next_action = -> { <<~HTML }
<h1>Hallo Next</h1>
<label for="example-input">Some input</label>
<inp... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | tasks/spec_tasks.rb | Ruby | mit | 206 | main | 444 | namespace :spec do
CAPYBARA_DRIVERS = %w[selenium cuprite]
desc "Run all tests for all drivers"
task :all do
CAPYBARA_DRIVERS.each do |driver|
run_specs driver
end
end
CAPYBARA_DRIVERS.each do |driver|
task driver do
run_specs driver
end
end
def run_specs(driver)
puts "R... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep.rb | Ruby | mit | 206 | main | 1,169 | require 'capybara'
selenium_loaded = begin
require 'selenium-webdriver'
true
rescue LoadError
false
end
cuprite_loaded = begin
require 'capybara/cuprite'
true
rescue LoadError
false
end
raise LoadError, "capybara-lockstep requires either selenium-webdriver or cuprite" unless selenium_loaded || cuprite_lo... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/lockstep.rb | Ruby | mit | 206 | main | 3,383 | module Capybara
module Lockstep
class << self
include Configuration
include Logging
include PageAccess
attr_accessor :synchronizing
alias synchronizing? synchronizing
def unsynchronize
return if mode == :off
client.synchronized = false
end
# Auto... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/util.rb | Ruby | mit | 206 | main | 502 | module Capybara
module Lockstep
module Util
class << self
def with_max_wait_time(seconds, &block)
old_max_wait_time = Capybara.default_max_wait_time
Capybara.default_max_wait_time = seconds
begin
block.call
ensure
Capybara.default_max_w... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/helper.rb | Ruby | mit | 206 | main | 1,096 | module Capybara
module Lockstep
module Helper
JS_PATH = File.expand_path('../helper.js', __FILE__)
HELPER_JS = IO.read(JS_PATH)
def capybara_lockstep_js(options = {})
HELPER_JS + capybara_lockstep_config_js(options)
end
def capybara_lockstep(options = {})
tag_optio... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/middleware.rb | Ruby | mit | 206 | main | 368 | module Capybara
module Lockstep
class Middleware
def initialize(app)
@app = app
end
def call(env)
tag = "Server request for #{env['PATH_INFO'] || 'unknown path'}"
Lockstep.start_work(tag)
begin
@app.call(env)
ensure
Lockstep.stop_wor... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/client.rb | Ruby | mit | 206 | main | 4,122 | module Capybara
module Lockstep
class Client
include Logging
include PageAccess
ERROR_SNIPPET_MISSING = 'Cannot synchronize: capybara-lockstep JavaScript snippet is missing'
ERROR_PAGE_MISSING = 'Cannot synchronize with empty page'
ERROR_ALERT_OPEN = 'Cannot synchronize while an ale... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/server.rb | Ruby | mit | 206 | main | 979 | module Capybara
module Lockstep
class Server
include Logging
def initialize
@job_count = 0
@job_count_mutex = Mutex.new
@idle_condition = ConditionVariable.new
end
attr_accessor :job_count
def start_work(tag)
job_count_mutex.synchronize do
... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/page_access.rb | Ruby | mit | 206 | main | 1,222 | module Capybara
module Lockstep
module PageAccess
def page
Capybara.current_session
end
delegate :evaluate_script, :evaluate_async_script, :execute_script, :driver, to: :page
def supported_driver?
selenium_driver? || cuprite_driver?
end
def alert_present?
... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/capybara_ext.rb | Ruby | mit | 206 | main | 9,259 | module Capybara
module Lockstep
module SynchronizeMacros
def self.extended(by)
by.instance_eval do
prepend(@synchronize_before_module = Module.new)
prepend(@synchronize_after_module = Module.new)
prepend(@unsynchronize_after_module = Module.new)
end
end
... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/logging.rb | Ruby | mit | 206 | main | 558 | module Capybara
module Lockstep
module Logging
def log(message)
if Lockstep.debug? && message.present?
message = "[capybara-lockstep] #{message}"
if is_logger?(Lockstep.debug)
# If someone set Capybara::Lockstep.debug to a logger, use that
Lockstep.debug.d... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/configuration.rb | Ruby | mit | 206 | main | 2,949 | module Capybara
module Lockstep
module Configuration
def timeout
@timeout.nil? ? Capybara.default_max_wait_time : @timeout
end
def timeout=(seconds)
@timeout = seconds
end
def timeout_with
@timeout_with.nil? ? :log : @timeout_with
end
def timeo... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/client/selenium.rb | Ruby | mit | 206 | main | 1,725 | module Capybara
module Lockstep
class Client::Selenium < Client
def with_synchronization_error_handling
yield
rescue ::Selenium::WebDriver::Error::ScriptTimeoutError
timeout_message = "Could not synchronize client within #{timeout} seconds"
log timeout_message
if timeo... |
github | makandra/capybara-lockstep | https://github.com/makandra/capybara-lockstep | lib/capybara-lockstep/client/cuprite.rb | Ruby | mit | 206 | main | 1,194 | module Capybara
module Lockstep
class Client::Cuprite < Client
def with_synchronization_error_handling
yield
rescue ::Ferrum::ScriptTimeoutError
timeout_message = "Could not synchronize client within #{timeout} seconds"
log timeout_message
if timeout_with == :error
... |
github | tyrauber/stock_quote | https://github.com/tyrauber/stock_quote | stock_quote.gemspec | Ruby | mit | 205 | master | 1,396 | # -*- encoding: utf-8 -*-
#$LOAD_PATH.push File.expand_path('../lib', __FILE__)
#require 'stock_quote/version'
Gem::Specification.new do |s|
s.name = 'stock_quote'
s.version = '4.0.0'
s.authors = ['Ty Rauber']
s.email = ['tyrauber@mac.com']
s.homepage = 'https://github.com/tyrauber/st... |
github | capistrano/rbenv | https://github.com/capistrano/rbenv | Rakefile | Ruby | mit | 205 | master | 222 | require "bundler/gem_tasks"
# Do nothing by default
task :default
Rake::Task["release"].enhance do
puts "Don't forget to publish the release on GitHub!"
system "open https://github.com/capistrano/rbenv/releases"
end |
github | capistrano/rbenv | https://github.com/capistrano/rbenv | capistrano-rbenv.gemspec | Ruby | mit | 205 | master | 936 | # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |gem|
gem.name = "capistrano-rbenv"
gem.version = '2.2.0'
gem.authors = ["Kir Shatrov", "Yamashita Yuu"]
gem.email = ["shatrov@me.c... |
github | capistrano/rbenv | https://github.com/capistrano/rbenv | lib/capistrano/tasks/rbenv.rake | Ruby | mit | 205 | master | 1,630 | namespace :rbenv do
task :validate do
on release_roles(fetch(:rbenv_roles)) do |host|
rbenv_ruby = fetch(:rbenv_ruby)
if rbenv_ruby.nil?
info 'rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv'
end
# don't check the rbenv_ruby_dir if :rbenv_r... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | Gemfile | Ruby | mit | 205 | master | 534 | source "https://rubygems.org"
# Declare your gem's dependencies in regressor.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | Rakefile | Ruby | mit | 205 | master | 400 | begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Regressor'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
r... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | regressor.gemspec | Ruby | mit | 205 | master | 1,068 | $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "regressor/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "regressor"
s.version = Regressor::VERSION
s.authors = ["Erwin Schens"]
s.email = ["erwin.schens@tutorize.com"]
s.h... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | spec/spec_helper.rb | Ruby | mit | 205 | master | 4,104 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require ... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | spec/lib/model/mongoid_model_spec.rb | Ruby | mit | 205 | master | 3,820 | require 'spec_helper'
require 'model/mongoid_model'
require 'model/expression'
require 'mongoid'
require 'fixtures/mongoid/models/dummy'
RSpec.describe Regressor::Model::MongoidModel do
subject { Regressor::Model::MongoidModel.new(Dummy) }
# === Regressor::Model::Mongoid::Database::Field ===
it { expect(subject... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/regressor.rb | Ruby | mit | 205 | master | 739 | module Regressor
class << self
attr_accessor :configuration
end
def self.configure
self.configuration ||= Configuration.new
yield(configuration) if block_given?
end
class Configuration
attr_accessor :regression_path,
:regression_controller_path,
:regressio... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/controller/regression.rb | Ruby | mit | 205 | master | 639 | require 'controller/util'
require 'controller/routing/rest/routes'
require 'controller/callback/after_filter'
require 'controller/callback/before_filter'
require 'controller/callback/around_filter'
module Regressor
module Controller
class Regression
include Rails.application.routes.url_helpers
includ... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/controller/util.rb | Ruby | mit | 205 | master | 680 | module Regressor
module Controller
module Util
def before_filters
filters(:before)
end
def after_filters
filters(:after)
end
def around_filters
filters(:around)
end
private
def filters(kind = nil)
controller = @controller.constant... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/controller/routing/rest/routes.rb | Ruby | mit | 205 | master | 4,316 | module Regressor
module Controller
module Routing
module Rest
module Routes
def rest_routes
controller_path = @controller.constantize.controller_path
@controller.constantize.action_methods.map do |action_method|
begin
journey_route = e... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/controller/callback/around_filter.rb | Ruby | mit | 205 | master | 299 | module Regressor
module Controller
module Callback
module AroundFilter
def around_callbacks
around_filters.map do |filter_name|
"it { should use_around_filter(#{filter_name}) }"
end.compact.uniq.join("\n ")
end
end
end
end
end |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/controller/callback/after_filter.rb | Ruby | mit | 205 | master | 296 | module Regressor
module Controller
module Callback
module AfterFilter
def after_callbacks
after_filters.map do |filter_name|
"it { should use_after_filter(#{filter_name}) }"
end.compact.uniq.join("\n ")
end
end
end
end
end |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/controller/callback/before_filter.rb | Ruby | mit | 205 | master | 299 | module Regressor
module Controller
module Callback
module BeforeFilter
def before_callbacks
before_filters.map do |filter_name|
"it { should use_before_filter(#{filter_name}) }"
end.compact.uniq.join("\n ")
end
end
end
end
end |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/templates/regressor.rb | Ruby | mit | 205 | master | 944 | # If the regressor gem is inside a group wrap your initializer in
# if defined?(Regressor) do .. end
Regressor.configure do |config|
# Defines the path where the generated files for your models will be placed
# config.regression_path = 'spec/models/regression'
# Defines the path where the generated files for you... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/generators/regressor/controller_generator.rb | Ruby | mit | 205 | master | 725 | require 'controller/regression'
module Regressor
class ControllerGenerator < Rails::Generators::Base
source_root(File.expand_path(File.dirname(__FILE__)))
def create_regression_files
Rails.application.eager_load!
ApplicationController.descendants.map(&:name).reject { |x| Regressor.configuration.... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/generators/regressor/factory_generator.rb | Ruby | mit | 205 | master | 1,189 | require 'model/factory_model'
module Regressor
class FactoryGenerator < Rails::Generators::Base
source_root(File.expand_path(File.dirname(__FILE__)))
def create_regression_files
load_application
generate_factories
end
private
def generate_factories
load_ar_models.each do |mod... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/generators/regressor/model_generator.rb | Ruby | mit | 205 | master | 1,440 | require 'model/active_record_model'
module Regressor
class ModelGenerator < ::Rails::Generators::Base
source_root(File.expand_path(File.dirname(__FILE__)))
argument :models, type: :array, default: [], banner: "models"
desc 'Create regression specs for activerecord models.'
def create_regression_fil... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/generators/regressor/install_generator.rb | Ruby | mit | 205 | master | 252 | module Regressor
class InstallGenerator < Rails::Generators::Base
source_root(File.expand_path(File.dirname(__FILE__)))
def copy_initializer
copy_file '../../templates/regressor.rb', 'config/initializers/regressor.rb'
end
end
end |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/generators/regressor/mongoid/model_generator.rb | Ruby | mit | 205 | master | 1,735 | require 'model/mongoid_model'
module Regressor
module Mongoid
class ModelGenerator < Rails::Generators::Base
source_root(File.expand_path(File.dirname(__FILE__)))
argument :models, type: :array, default: [], banner: "models"
desc 'Create regression specs for mongoid models.'
def create_... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/factory_model.rb | Ruby | mit | 205 | master | 221 | module Regressor
module Model
class FactoryModel
# === Attribute Accessors ===
attr_accessor :model
# === Methods ===
def initialize(model)
@model = model
end
end
end
end |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/expression.rb | Ruby | mit | 205 | master | 771 | module Regressor
module Model
class Expression
attr_accessor :subject, :expectation, :matcher, :matcher_expectation, :modification
def initialize(subject, expectation, matcher, matcher_expectation, modification = nil)
self.subject = subject
self.expectation = expectation
self... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid_model.rb | Ruby | mit | 205 | master | 857 | require 'model/expression'
require 'model/mongoid/database/field'
require 'model/mongoid/relation/has_many'
require 'model/mongoid/relation/has_one'
require 'model/mongoid/relation/belongs_to'
require 'model/mongoid/relation/embedded'
require 'model/mongoid/document/timestamp'
require 'model/mongoid/document/version'
... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/active_record_model.rb | Ruby | mit | 205 | master | 1,305 | require_relative 'active_record/util'
require_relative 'active_record/relation/belong_to'
require_relative 'active_record/relation/has_and_belongs_to_many'
require_relative 'active_record/relation/has_one'
require_relative 'active_record/relation/has_many'
require_relative 'active_record/validation/presence'
require_re... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/database/field.rb | Ruby | mit | 205 | master | 749 | module Regressor
module Model
module Mongoid
module Database
module Field
def fields_as_string
fields.join("\n ")
end
def fields
@model.fields.keys.map do |field|
::Regressor::Model::Expression.new(:is_expected,
... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/relation/belongs_to.rb | Ruby | mit | 205 | master | 593 | module Regressor
module Model
module Mongoid
module Relation
module BelongsTo
def belongs_to_relations_as_string
belongs_to_relations.join("\n ")
end
def belongs_to_relations
@model.reflect_on_all_associations(:belongs_to).map(&:name).map do |... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/relation/embedded.rb | Ruby | mit | 205 | master | 787 | module Regressor
module Model
module Mongoid
module Relation
module Embedded
def embedded_relations_as_string
embedded_relations.join("\n ")
end
def embedded_relations
@model.embedded_relations.keys.map do |key|
macro = @model.em... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/relation/has_one.rb | Ruby | mit | 205 | master | 577 | module Regressor
module Model
module Mongoid
module Relation
module HasOne
def has_one_relations_as_string
has_one_relations.join("\n ")
end
def has_one_relations
@model.reflect_on_all_associations(:has_one).map(&:name).map do |relation|
... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/relation/has_many.rb | Ruby | mit | 205 | master | 583 | module Regressor
module Model
module Mongoid
module Relation
module HasMany
def has_many_relations_as_string
has_many_relations.join("\n ")
end
def has_many_relations
@model.reflect_on_all_associations(:has_many).map(&:name).map do |relation|
... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/document/timestamp.rb | Ruby | mit | 205 | master | 1,355 | module Regressor
module Model
module Mongoid
module Document
module Timestamp
def timestamp_includes
included_timestamp_modules.map do |module_included|
"it { is_expected.to #{timestamp_module(module_included)} }"
end.join("\n ")
end
... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/mongoid/document/version.rb | Ruby | mit | 205 | master | 521 | module Regressor
module Model
module Mongoid
module Document
module Version
def version_include
if versioning_included?
"it { is_expected.to be_versioned_document }"
else
"it { is_expected.not_to be_versioned_document }"
end
... |
github | erwinjunker/regressor | https://github.com/erwinjunker/regressor | lib/model/active_record/validation.rb | Ruby | mit | 205 | master | 1,122 | module Regressor
module Model
module Validation
def wrap_conditional_validations validator, specs
if_mock = if_condition_mock validator
unless_mock = unless_condition_mock validator
padding = if_mock.blank? && unless_mock.blank? ? '' : ' '
specs = specs.map do |spec|
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.