├── .gitignore ├── .rspec ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib └── ngrok │ ├── rspec.rb │ └── rspec │ └── version.rb ├── ngrok-rspec.gemspec └── spec ├── ngrok-rspec └── ngrok-rspec_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in ngrok-rspec.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Anton Bogdanovich 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ngrok::Rspec 2 | 3 | Ngrok-rspec gem provides ability to run capybara specs through ngrok. 4 | 5 | [![Gem Version](https://badge.fury.io/rb/ngrok-rspec.svg)](http://badge.fury.io/rb/ngrok-rspec) [![Code Climate](https://codeclimate.com/github/bogdanovich/ngrok-rspec/badges/gpa.svg)](https://codeclimate.com/github/bogdanovich/ngrok-rspec) 6 | 7 | ## Installation 8 | 9 | *Note:* You must have ngrok **v2+** installed available in your `PATH`. 10 | 11 | Add this line to your application's Gemfile: 12 | 13 | ```ruby 14 | group :test do 15 | gem 'ngrok-rspec' 16 | end 17 | ``` 18 | 19 | And then execute: 20 | 21 | $ bundle 22 | 23 | Or install it yourself as: 24 | 25 | $ gem install ngrok-rspec 26 | 27 | ## Usage 28 | 29 | Configure rspec 30 | ```ruby 31 | RSpec.configure do |config| 32 | # any port can be used 33 | Capybara.server_port = 3001 34 | Ngrok::Rspec.tunnel = { port: Capybara.server_port } 35 | 36 | config.include Ngrok::Rspec 37 | end 38 | ``` 39 | 40 | Write specs using filter ngrok: true 41 | 42 | ```ruby 43 | context "Using ngrok", ngrok: true do 44 | it "should use ngrok tunnel" do 45 | # your test code 46 | end 47 | end 48 | ``` 49 | 50 | Custom tunnel options available: 51 | 52 | ```ruby 53 | # custom tunnel options 54 | Ngrok::Rspec.tunnel = { 55 | port: Capybara.server_port, 56 | subdomain: 'MY_SUBDOMAIN', 57 | authtoken: 'MY_TOKEN', 58 | log: 'ngrok.log', 59 | config: '~/.ngrok' 60 | } 61 | ``` 62 | 63 | 64 | ## Contributing 65 | 66 | 1. Fork it ( https://github.com/bogdanovich/ngrok-rspec/fork ) 67 | 2. Create your feature branch (`git checkout -b my-new-feature`) 68 | 3. Commit your changes (`git commit -am 'Add some feature'`) 69 | 4. Push to the branch (`git push origin my-new-feature`) 70 | 5. Create a new Pull Request 71 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /lib/ngrok/rspec.rb: -------------------------------------------------------------------------------- 1 | require "ngrok/rspec/version" 2 | require "ngrok/tunnel" 3 | 4 | module Ngrok 5 | 6 | class UnknownServerPort < StandardError; end 7 | 8 | module Rspec 9 | class << self; attr_accessor :original_app_host, :tunnel; end 10 | 11 | def self.included(base) 12 | 13 | Ngrok::Rspec.original_app_host = Capybara.app_host 14 | 15 | ::RSpec.configure do |config| 16 | 17 | config.around(:each, ngrok: true) do |example| 18 | raise UnknownServerPort, "Define Capybara.server_port in RSpec.config" unless Capybara.server_port 19 | Ngrok::Tunnel.start(Ngrok::Rspec.tunnel) unless Ngrok::Tunnel.running? 20 | 21 | Capybara.app_host = Ngrok::Tunnel.ngrok_url 22 | 23 | example.run 24 | 25 | Capybara.app_host = Ngrok::Rspec::original_app_host 26 | end 27 | 28 | config.after(:suite) do 29 | Ngrok::Tunnel.stop if Ngrok::Tunnel.running? 30 | end 31 | 32 | end 33 | end 34 | 35 | 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/ngrok/rspec/version.rb: -------------------------------------------------------------------------------- 1 | module Ngrok 2 | module Rspec 3 | VERSION = "1.1.18" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /ngrok-rspec.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'ngrok/rspec/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "ngrok-rspec" 8 | spec.version = Ngrok::Rspec::VERSION 9 | spec.authors = ["Anton Bogdanovich"] 10 | spec.email = ["27bogdanovich@gmail.com"] 11 | spec.summary = %q{Ngrok-rspec gem - run capybara specs with ngrok tunnel} 12 | spec.description = %q{Ngrok-rspec gem provides ability to run capybara specs with ngrok tunnel} 13 | spec.homepage = "https://github.com/bogdanovich/ngrok-rspec" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_dependency "ngrok-tunnel", "~> 2.0" 22 | spec.add_dependency "rspec", ">= 2.99" 23 | spec.add_dependency "capybara", ">= 2.4" 24 | 25 | spec.add_development_dependency "pry", "~> 0.10" 26 | spec.add_development_dependency "pry-byebug", "~> 2.0" 27 | spec.add_development_dependency "bundler", "~> 1.7" 28 | spec.add_development_dependency "rake", "~> 10.0" 29 | spec.add_development_dependency "poltergeist", "~> 1.5" 30 | spec.add_development_dependency "selenium-webdriver", "~> 2.43" 31 | 32 | end 33 | -------------------------------------------------------------------------------- /spec/ngrok-rspec/ngrok-rspec_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Ngrok::Rspec do 4 | 5 | context "without ngrok" do 6 | it "should have default app_host" do 7 | app_host = Capybara.app_host 8 | expect(app_host).to be_nil 9 | end 10 | end 11 | 12 | context "with ngrok", ngrok: true do 13 | it "should have ngrok app_host" do 14 | expect(Capybara.app_host =~ /ngrok\.io$/).to_not be_nil 15 | end 16 | end 17 | 18 | context "after ngrok" do 19 | it "should have default app host" do 20 | expect(Capybara.app_host =~ /ngrok\.io$/).to be_nil 21 | end 22 | end 23 | 24 | end 25 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'pry' 2 | require 'capybara/rspec' 3 | require 'capybara/poltergeist' 4 | require 'ngrok/tunnel' 5 | require 'ngrok/rspec' 6 | 7 | 8 | RSpec.configure do |config| 9 | config.expect_with :rspec do |expectations| 10 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 11 | end 12 | 13 | config.mock_with :rspec do |mocks| 14 | mocks.verify_partial_doubles = true 15 | end 16 | 17 | config.include Capybara::DSL 18 | 19 | Capybara.server_port = 3001 20 | Ngrok::Rspec.tunnel = {port: Capybara.server_port} 21 | 22 | config.include Ngrok::Rspec 23 | 24 | 25 | Capybara.register_driver :poltergeist do |app| 26 | Capybara::Poltergeist::Driver.new(app, 27 | :phantomjs_options => ['--debug=no', '--load-images=no', '--ignore-ssl-errors=yes', '--ssl-protocol=any'], :debug => false) 28 | end 29 | 30 | NGROK_SPEC_DEBUG = ENV['NGROK_SPEC_DEBUG'] || false 31 | if NGROK_SPEC_DEBUG 32 | Capybara.default_driver = :selenium 33 | else 34 | Capybara.default_driver = :poltergeist 35 | Capybara.javascript_driver = :poltergeist 36 | end 37 | end 38 | --------------------------------------------------------------------------------