Skip to content
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

Generalized tips #110

Merged
merged 4 commits into from
Jun 9, 2018
Merged
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'mumukit-core', '~> 1.1'
gem 'mumukit-bridge', '~> 3.5'
gem 'mumukit-nuntius', '~> 6.1'
gem 'mumukit-inspection', '~> 3.2'
gem 'mumukit-assistant', '~> 0.1'

gem 'mumukit-auth', '~> 7.0'
gem 'mumukit-service', '~> 3.0'
Expand Down
7 changes: 5 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ GEM
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
mumukit-assistant (0.1.1)
mumukit-core (~> 1.3)
mumukit-auth (7.2.0)
jwt (~> 1.5)
mumukit-core (~> 1.0)
Expand All @@ -54,7 +56,7 @@ GEM
mumukit-core (~> 1.0)
redcarpet (~> 3.3.2)
rouge (~> 3.1)
mumukit-core (1.2.2)
mumukit-core (1.3.0)
activesupport (>= 4.1)
i18n (~> 0.7)
rack (>= 1.5)
Expand Down Expand Up @@ -110,7 +112,7 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.9.0)
puma (3.7.1)
rack (1.6.9)
rack (1.6.10)
rack-protection (1.5.5)
rack
rack-test (0.6.3)
Expand Down Expand Up @@ -167,6 +169,7 @@ DEPENDENCIES
codeclimate-test-reporter
factory_girl
git
mumukit-assistant (~> 0.1)
mumukit-auth (~> 7.0)
mumukit-bridge (~> 3.5)
mumukit-content-type (~> 1.3)
Expand Down
1 change: 1 addition & 0 deletions lib/bibliotheca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'mumukit/login'
require 'mumukit/platform'
require 'mumukit/inspection'
require 'mumukit/assistant'

class Mumukit::Auth::Slug
def rebase(new_organizaton)
Expand Down
3 changes: 2 additions & 1 deletion lib/bibliotheca/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def errors
('Description must be present' unless description.present?),
("Invalid extra_visible flag #{extra_visible}" unless [nil, true, false].include? extra_visible),
("Invalid manual_evaluation flag #{manual_evaluation}" unless [nil, true, false].include? manual_evaluation),
("Invalid expectations" unless expectations.all? { |it| Mumukit::Inspection::parse(it["inspection"]) rescue false })
("Invalid expectations" unless expectations.all? { |it| Mumukit::Inspection::parse(it["inspection"]) rescue false }),
("Invalid assistance_rules" unless (Mumukit::Assistant.parse assistance_rules.map &:deep_symbolize_keys rescue false))
].compact
end
end
Expand Down
10 changes: 0 additions & 10 deletions lib/bibliotheca/io/exercise_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ def locale
meta['locale']
end

def expectations_list
if [:playground, :reading].include? type
nil
else
(expectations || []).map do |e|
{binding: e['binding'], inspection: e['inspection']}
end
end
end

def build
build_metadata.merge(build_simple_fields).compact
end
Expand Down
10 changes: 9 additions & 1 deletion lib/bibliotheca/io/exercise_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ def yaml(root, filename)
read_yaml_file "#{root}/#{filename}.yml"
end

def yaml_list(root, filename, key)
yaml(root, filename).try { |it| it[key] }
end

def meta(root)
yaml(root, 'meta')
end

def expectations(root)
yaml(root, 'expectations')
yaml_list(root, 'expectations', 'expectations')
end

def assistance_rules(root)
yaml_list(root, 'assistance_rules', 'rules')
end
end
end
3 changes: 2 additions & 1 deletion lib/bibliotheca/io/guide_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def read_exercises
builder.test = exercise_reader.test_code(root)
builder.extra = exercise_reader.extra(root)
builder.default = exercise_reader.default(root)
builder.expectations = exercise_reader.expectations(root).try { |it| it['expectations'] }
builder.expectations = exercise_reader.expectations(root)
builder.assistance_rules = exercise_reader.assistance_rules(root)
yield builder
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/bibliotheca/schema/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def self.fields_schema
{name: :choices, kind: :metadata, default: []},

{name: :expectations, kind: :file, extension: 'yml',
transform: proc { |it| {'expectations' => it.map(&:stringify_keys)}.to_yaml },
default: []},
transform: yaml_list('expectations'), default: []},

{name: :assistance_rules, kind: :file, extension: 'yml',
transform: yaml_list('rules'), default: []},

{name: :goal, kind: :metadata},
{name: :test, kind: :file, extension: :test},
Expand All @@ -37,6 +39,10 @@ def self.fields_schema
]
end

def self.yaml_list(key)
proc { |it| {key => it.map(&:stringify_keys)}.to_yaml }
end

def self.new_field(it)
Field.new(it)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/exercise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,10 @@
let(:exercise) { build(:exercise, expectations: [{ "binding" => "program", "inspection" => "" }]) }
it { expect { exercise.validate! }.to raise_error(Mumukit::Service::DocumentValidationError, "Invalid expectations") }
end

context 'invalid assistance_rules' do
let(:exercise) { build(:exercise, assistance_rules: [{ when: 'content_empty', then: ['asd'] }]) }
it { expect { exercise.validate! }.to raise_error(Mumukit::Service::DocumentValidationError, "Invalid assistance_rules") }
end
end
end
5 changes: 4 additions & 1 deletion spec/routes/guides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
test: %Q{describe "foo" $ do\n it "bar" $ do\n foo = True}, solution: 'foo = True',
manual_evaluation: false,
choices: [],
expectations: [{ "binding" => 'foo', "inspection" => 'HasBinding'}], tag_list: [], extra_visible: false} }
expectations: [{"binding" => 'foo', "inspection" => 'HasBinding'}],
assistance_rules: [{"when" => 'content_empty', "then" => 'a message'}],
tag_list: [],
extra_visible: false} }

let!(:guide_id) {
Bibliotheca::Collection::Guides.insert!(
Expand Down