Skip to content

Display captured exceptions in specs #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions config/initializers/administrate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'administrate/field/associative'

module Administrate
module Field
class Associative < Base
module Overrides
def deprecated_option(name)
name == :class_name ? options.fetch(name) : super
end
end
end
end
end

# Ref: https://github.com/thoughtbot/administrate/commit/f9c5f1af0bd27dbe8e98d43b2074b96004689ad5
patch_required = Gem::Version.new(Administrate::VERSION) >= Gem::Version.new('1.0.0.beta3')
raise 'Administrate::Field::Associative::Overrides patch is no longer required' if patch_required

Administrate::Field::Associative.prepend(Administrate::Field::Associative::Overrides)
6 changes: 5 additions & 1 deletion lib/for_education_code_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
class ForEducationCodeGenerator
MAX_CODE = 1_000_000

cattr_accessor :random

self.random ||= Random.new

def self.generate
number = Random.new.rand(MAX_CODE)
number = random.rand(MAX_CODE)
code = format('%06d', number)

code.match(/(\d\d)(\d\d)(\d\d)/) do |m|
Expand Down
3 changes: 2 additions & 1 deletion spec/concepts/project/create_remix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@

it 'persists the new component' do
remixed_project = create_remix[:project]
expect(remixed_project.components.first.attributes.symbolize_keys).to include(new_component_params)
new_component = remixed_project.components.find { |c| c.name == new_component_params[:name] }
expect(new_component.attributes.symbolize_keys).to include(new_component_params)
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/concepts/school_teacher/invite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
expect(response.success?).to be(true)
end

it 'does not return an error in operation response' do
response = described_class.call(school:, school_teacher_params:, token:)
expect(response[:error]).to be_blank
end

it 'creates a TeacherInvitation' do
expect { described_class.call(school:, school_teacher_params:, token:) }.to change(TeacherInvitation, :count)
end
Expand Down
4 changes: 1 addition & 3 deletions spec/lib/for_education_code_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
RSpec.describe ForEducationCodeGenerator do
describe '.generate' do
it 'uses Random#rand to generate a random number up to the maximum' do
random = instance_double(Random)
allow(random).to receive(:rand).with(ForEducationCodeGenerator::MAX_CODE).and_return(123)
allow(Random).to receive(:new).and_return(random)
allow(described_class.random).to receive(:rand).with(ForEducationCodeGenerator::MAX_CODE).and_return(123)

expect(described_class.generate).to eq('00-01-23')
end
Expand Down
3 changes: 2 additions & 1 deletion spec/models/school_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
require 'rails_helper'

RSpec.describe SchoolProject do
pending "add some examples to (or delete) #{__FILE__}"
it { is_expected.to belong_to(:school) }
it { is_expected.to belong_to(:project) }
end
8 changes: 8 additions & 0 deletions spec/support/faker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

RSpec.configure do |config|
config.before(:suite) do
puts "Faker randomized with seed #{config.seed}"
Faker::Config.random = Random.new(config.seed)
end
end
8 changes: 8 additions & 0 deletions spec/support/for_education_code_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

RSpec.configure do |config|
config.before(:suite) do
puts "ForEducationCodeGenerator randomized with seed #{config.seed}"
ForEducationCodeGenerator.random = Random.new(config.seed)
end
end