|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe TatlTael::Linter do |
| 4 | + shared_examples "yields" do |raw_changes| |
| 5 | + let(:changes) { raw_changes.map { |c| double(c) } } |
| 6 | + |
| 7 | + it "yields" do |
| 8 | + expect { |b| subject.ensure_specs(&b) }.to yield_with_no_args |
| 9 | + end |
| 10 | + end |
| 11 | + |
| 12 | + shared_examples "does not yield" do |raw_changes| |
| 13 | + let(:changes) { raw_changes.map { |c| double(c) } } |
| 14 | + |
| 15 | + it "does not yield" do |
| 16 | + expect { |b| subject.ensure_specs(&b) }.not_to yield_with_no_args |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + shared_examples "change combos" do |change_path| |
| 21 | + context "not deletion" do |
| 22 | + context "no spec changes" do |
| 23 | + include_examples "yields", |
| 24 | + [{ path: change_path, deleted?: false }] |
| 25 | + end |
| 26 | + context "has spec non deletions" do |
| 27 | + include_examples "does not yield", |
| 28 | + [{ path: change_path, deleted?: false }, |
| 29 | + { path: SPEC_CHANGE, deleted?: false }] |
| 30 | + include_examples "does not yield", |
| 31 | + [{ path: change_path, deleted?: false }, |
| 32 | + { path: SPEC_CANVAS_CHANGE, deleted?: false }] |
| 33 | + include_examples "does not yield", |
| 34 | + [{ path: change_path, deleted?: false }, |
| 35 | + { path: TEST_CHANGE, deleted?: false }] |
| 36 | + end |
| 37 | + context "has spec deletions" do |
| 38 | + include_examples "yields", |
| 39 | + [{ path: change_path, deleted?: false }, |
| 40 | + { path: SPEC_CHANGE, deleted?: true }] |
| 41 | + include_examples "yields", |
| 42 | + [{ path: change_path, deleted?: false }, |
| 43 | + { path: SPEC_CANVAS_CHANGE, deleted?: true }] |
| 44 | + include_examples "yields", |
| 45 | + [{ path: change_path, deleted?: false }, |
| 46 | + { path: TEST_CHANGE, deleted?: true }] |
| 47 | + end |
| 48 | + end |
| 49 | + context "deletion" do |
| 50 | + include_examples "does not yield", |
| 51 | + [{ path: change_path, deleted?: true }] |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + let(:subject) { TatlTael::Linter.new(git_dir: ".") } |
| 56 | + |
| 57 | + SPEC_CHANGE = "spec/controllers/accounts_controller_spec.rb" |
| 58 | + SPEC_CANVAS_CHANGE = "spec_canvas/selenium/analytics_course_view_spec.rb" |
| 59 | + TEST_CHANGE = "gems/acts_as_list/test/list_test.rb" |
| 60 | + |
| 61 | + APP_RB_PATH = "app/controllers/accounts_controller.rb" |
| 62 | + APP_ERB_PATH = "app/views/announcements/index.html.erb" |
| 63 | + APP_JSX_PATH = "app/jsx/editor/SwitchEditorControl.jsx" |
| 64 | + APP_COFFEE_PATH = "app/coffeescripts/calendar/CalendarEvent.coffee" |
| 65 | + LIB_RB_PATH = "lib/api_routes.rb" |
| 66 | + PUBLIC_HTML_PATH = "public/partials/_license_help.html" |
| 67 | + PUBLIC_JS_PATH = "public/javascripts/account_settings.js" |
| 68 | + PUBLIC_BOWER_JS_PATH = "public/javascripts/bower/axios/dist/axios.amd.js" |
| 69 | + PUBLIC_ME_JS_PATH = "public/javascripts/mediaelement/mep-feature-speed-instructure.js" |
| 70 | + PUBLIC_VENDOR_JS_PATH = "public/javascripts/vendor/bootstrap/bootstrap-dropdown.js" |
| 71 | + |
| 72 | + before(:each) do |
| 73 | + allow(subject).to receive(:changes).and_return(changes) |
| 74 | + end |
| 75 | + |
| 76 | + describe "#ensure_specs" do |
| 77 | + context "in app" do |
| 78 | + context "has ruby changes" do |
| 79 | + include_examples "change combos", APP_RB_PATH |
| 80 | + end |
| 81 | + context "has erb changes" do |
| 82 | + include_examples "change combos", APP_ERB_PATH |
| 83 | + end |
| 84 | + context "has jsx changes" do |
| 85 | + include_examples "change combos", APP_JSX_PATH |
| 86 | + end |
| 87 | + context "has coffee changes" do |
| 88 | + include_examples "change combos", APP_COFFEE_PATH |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + context "in lib" do |
| 93 | + context "has ruby changes" do |
| 94 | + include_examples "change combos", LIB_RB_PATH |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + context "in public" do |
| 99 | + context "has html changes" do |
| 100 | + include_examples "change combos", PUBLIC_HTML_PATH |
| 101 | + end |
| 102 | + context "has js changes" do |
| 103 | + include_examples "change combos", PUBLIC_JS_PATH |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + context "in excluded public sub dirs" do |
| 108 | + context "bower" do |
| 109 | + include_examples "does not yield", |
| 110 | + [{ path: PUBLIC_BOWER_JS_PATH, deleted?: false }] |
| 111 | + end |
| 112 | + context "mediaelement" do |
| 113 | + include_examples "does not yield", |
| 114 | + [{ path: PUBLIC_ME_JS_PATH, deleted?: false }] |
| 115 | + end |
| 116 | + context "vendor" do |
| 117 | + include_examples "does not yield", |
| 118 | + [{ path: PUBLIC_VENDOR_JS_PATH, deleted?: false }] |
| 119 | + end |
| 120 | + end |
| 121 | + end |
| 122 | +end |
0 commit comments